-
Notifications
You must be signed in to change notification settings - Fork 143
134 lines (119 loc) · 4.32 KB
/
update-draft-hips.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Update Draft HIPs Data
on:
schedule:
- cron: "0 */6 * * *" # Runs every 6 hours
workflow_dispatch: # Allows manual triggering
jobs:
update-draft-hips:
if: github.ref == 'refs/heads/main' # Only run on main branch
runs-on: improvement-proposals-linux-medium
permissions:
contents: write
pull-requests: read
steps:
- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
token: ${{ secrets.GH_ACCESS_TOKEN }}
- name: Import GPG Key
id: gpg_importer
uses: step-security/ghaction-import-gpg@6c8fe4d0126a59d57c21f87c9ae5dd3451fa3cca # v6.1.0
with:
git_commit_gpgsign: true
git_tag_gpgsign: true
git_user_signingkey: true
gpg_private_key: ${{ secrets.GPG_KEY_CONTENTS }}
passphrase: ${{ secrets.GPG_KEY_PASSPHRASE }}
- name: Setup Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: "20"
- name: Create Script
run: |
mkdir -p _data
cat << 'EOF' > fetch-draft-hips.js
const https = require('https');
async function makeGraphQLRequest(query, token) {
return new Promise((resolve, reject) => {
const options = {
hostname: 'api.github.com',
path: '/graphql',
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'User-Agent': 'Node.js'
}
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', chunk => { data += chunk; });
res.on('end', () => resolve(JSON.parse(data)));
});
req.on('error', reject);
req.write(JSON.stringify({ query }));
req.end();
});
}
async function getAllPRs() {
const query = `
query {
repository(name: "hedera-improvement-proposal", owner: "hashgraph") {
pullRequests(first: 100, states: [OPEN], orderBy: {field: CREATED_AT, direction: DESC}) {
nodes {
title
number
url
headRefOid
files(first: 100) {
edges {
node {
path
additions
deletions
}
}
}
author {
login
}
}
}
}
}
`;
try {
const result = await makeGraphQLRequest(query, process.env.GITHUB_TOKEN);
if (result.errors) {
console.error('GraphQL errors:', result.errors);
process.exit(1);
}
return result.data.repository.pullRequests.nodes;
} catch (error) {
console.error('Error fetching PRs:', error);
throw error;
}
}
// Run the main function
getAllPRs().then(prs => {
const fs = require('fs');
fs.writeFileSync('_data/draft_hips.json', JSON.stringify(prs, null, 2));
}).catch(error => {
console.error('Failed to fetch PRs:', error);
process.exit(1);
});
EOF
- name: Run Script
run: node fetch-draft-hips.js
env:
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
- name: Commit and Push Changes
env:
GITHUB_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
GITHUB_USER_NAME: ${{ secrets.GIT_USER_NAME }}
run: |
git config --local user.email "$GITHUB_USER_EMAIL"
git config --local user.name "$GITHUB_USER_NAME"
git add _data/draft_hips.json
git commit -s -S -m "Update draft HIPs data [skip ci]" || echo "No changes to commit"
git push origin main || echo "No changes to push"