forked from whitescent/KFC-Crazy-Thursday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (84 loc) · 2.4 KB
/
index.js
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
require('dotenv').config();
const { Octokit } = require('@octokit/rest');
const axios = require('axios').default;
const {
GH_TOKEN
} = process.env;
const owner = "Nthily";
const repo = "KFC-Crazy-Thursday";
var jsonAry = [];
var jsonStr = "";
(async () => {
try {
const octokit = new Octokit({
auth: GH_TOKEN,
});
const response = await octokit.rest.issues.listForRepo({
owner: owner,
repo: repo,
labels: "文案提供",
state: "all"
});
const issuesBody = response.data;
issuesBody.forEach(value => {
jsonAry.push({
text: value.body
});
})
jsonStr = JSON.stringify(jsonAry, null, 2);
console.log(jsonStr);
const {
data: { sha: jsonSha }
} = await octokit.git.createBlob({
owner: owner,
repo: repo,
content: jsonStr
});
const commits = await octokit.repos.listCommits({
owner: owner,
repo: repo,
});
const lastSha = commits.data[0].sha;
const {
data: { sha: treeSHA }
} = await octokit.git.createTree({
owner: owner,
repo: repo,
tree: [
{
mode: '100644',
path: "kfc.json",
type: "blob",
sha: jsonSha
}
],
base_tree: lastSha,
});
const {
data: { sha: newSHA }
} = await octokit.git.createCommit({
owner: owner,
repo: repo,
author: {
name: "github-actions[bot]",
email: "41898282+github-actions[bot]@users.noreply.github.com",
},
committer: {
name: "github-actions[bot]",
email: "41898282+github-actions[bot]@users.noreply.github.com",
},
tree: treeSHA,
message: 'Generate kfc.json',
parents: [ lastSha ],
});
const result = await octokit.git.updateRef({
owner: owner,
repo: repo,
ref: "heads/main",
sha: newSHA,
});
console.log(`result: ${result}`);
} catch(err) {
console.error(`生成 Json 文件时发生了错误:${err}`);
}
})();