-
Notifications
You must be signed in to change notification settings - Fork 44
179 lines (156 loc) · 6.31 KB
/
07-sync-integration-info.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: deployed feedback
on:
workflow_dispatch:
jobs:
sync-info:
name: record
runs-on: ubuntu-latest
steps:
- name: install depends for load scripts
run: |
npm install @octokit/[email protected]
npm install @octokit/[email protected]
npm install js-yaml
- name: Get token using github-script
id: get-token
uses: actions/github-script@v6
env:
APP_ID: 229710
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
with:
script: |
global["fetch"] = fetch
const { Octokit } = require("@octokit/rest");
const { createAppAuth } = require("@octokit/auth-app");
const appOctokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId: process.env.APP_ID,
privateKey: process.env.APP_PRIVATE_KEY,
}
});
const app_installation = await appOctokit.rest.apps.getRepoInstallation({
owner: context.payload.organization.login,
repo: context.payload.repository.name
});
const { token } = await appOctokit.auth({
type: "installation",
installationId: app_installation.data.id
});
core.setOutput('app_token', token)
- name: get_info
id: get_info
shell: python
env:
GITHUB_TOKEN: ${{ steps.get-token.outputs.app_token }}
run: |
import requests
import yaml
import os
import logging
import json
import string
header = {
"Accept": "application/vnd.github+json",
"Authorization":"Bearer " + os.environ.get("GITHUB_TOKEN")
}
illegalTags = []
illegalRepos = []
def set_output(name, value):
output_file = os.environ.get("GITHUB_OUTPUT")
with open(output_file, "a") as output:
output.write(name + "=" + value + "\n")
def get_pulls_info():
get_info_url= 'https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}'
res = requests.get(get_info_url,header)
json_str = json.loads(res.text)
get_body = json_str['body']
get_user_name = json_str['user']['login']
set_output("login_id", str(get_user_name))
return get_body
def analyze_info(str):
for data in str.split('\n'):
if data.find("repo") == 0:
repo = data.split(':')[1].strip()
illegalRepos.append(repo)
elif data.find("tag") == 0:
tag = data.split(':')[1].strip()
illegalTags.append({"repo": repo, "tag": tag})
try:
analyze_info(get_pulls_info())
print(illegalTags)
if len(illegalTags) > 0:
set_output("illegal_tags", str(illegalTags))
else:
set_output("illegal_tags", "undefined")
if len(illegalTags) > 0:
set_output("illegal_repos", str(illegalRepos))
else:
set_output("illegal_repos", "undefined")
except BaseException as e:
logging.error(e)
exit(-10)
- name: update records
uses: actions/github-script@v6
if: ${{ steps.get_info.outputs.login_id == 'deepin-tagger'}}
with:
github-token: ${{ steps.get-token.outputs.app_token }}
script: |
const yaml = require('js-yaml');
const newIntergrated = ${{ steps.get_info.outputs.illegal_tags }}
const {data} = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: "records.yml",
});
datas = Buffer.from(data.content, data.encoding)
recordsContent = yaml.load(datas.toString())
if ( recordsContent.records === null || recordsContent.records === undefined ) {
recordsContent.records = {}
}
newIntergrated.forEach(repo => {
recordsContent.records[repo.repo] = {"ver": repo.tag, "date": new Date().toISOString().split('T')[0], "pr": ${{ github.event.number }}}
})
const contentString = yaml.dump(recordsContent, {'sortKeys': true ,indent: 4})
let contentBinary = Buffer.from(contentString).toString("base64")
await github.rest.repos.createOrUpdateFileContents({
owner: context.repo.owner,
repo: context.repo.repo,
sha: data.sha,
path: "records.yml",
message: "update records from https://github.com/${{ github.repository }}/pull/${{ github.event.number }}",
content: contentBinary,
branch: "master",
})
- name: label intergerted
uses: actions/github-script@v6
if: ${{ steps.get_info.outputs.login_id == 'deepin-tagger'}}
with:
github-token: ${{ github.token }}
script: |
const { data } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const labeled = (data.find(label => label.name === "Merged") !== undefined)
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['Merged']
})
- name: close this pull request
if: ${{ steps.get_info.outputs.login_id == 'deepin-tagger'}}
shell: python
env:
GITHUB_TOKEN: ${{ steps.get-token.outputs.app_token }}
run: |
import requests
import os
headers = {
"Accept": "application/vnd.github+json",
"Authorization":"Bearer " + os.environ.get("GITHUB_TOKEN")
}
res = requests.patch(url="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}",
headers=headers, json= {'state': 'closed'})