1 function getGithubAccount(package) {
2 var toml
= require("toml");
3 var fs
= require("fs");
4 var tomlFileContent
= fs
.readFileSync(
5 ".github/workflows/overlay.toml",
9 github_account
= toml
.parse(tomlFileContent
)[package]["github_account"];
11 return github_account
;
14 function randomSort(a
, b
) {
15 return 0.5 - Math
.random();
18 module
.exports
= async ({ github
, context
, core
}) => {
19 // hardcode gentoo-zh official repo name
20 var gentoo_zh_official_repo_name
= "microcai/gentoo-zh";
21 var repo_name
= process
.env
.GITHUB_REPOSITORY
;
22 var repo_is_gentoo_zh_official
= repo_name
== gentoo_zh_official_repo_name
;
24 let pkgs
= JSON
.parse(process
.env
.pkgs
);
25 const SEARCH_MAX_REMAINING
= 30;
26 var pkgs_gt_search_limit
= pkgs
.length
> SEARCH_MAX_REMAINING
;
28 if (pkgs_gt_search_limit
) {
29 pkgs
.sort(randomSort
);
32 for (let pkg
of pkgs
) {
33 // // limit "x11-misc/9menu" and "dev-libs/libthai"
34 // if (pkg.name != "x11-misc/9menu" && pkg.name != "dev-libs/libthai") {
37 if (pkgs_gt_search_limit
) {
38 const { data
: rate_limit_data
} = await github
.request("/rate_limit");
39 if (rate_limit_data
.resources
.search
.remaining
== 0) {
40 core
.warning(`cause rate limit, failed to search ${pkg.name}'s issues`);
45 titlePrefix
= "[nvchecker] " + pkg
.name
+ " can be bump to ";
46 title
= titlePrefix
+ pkg
.newver
;
48 if (pkg
.oldver
!= null) {
49 body
+= "oldver: " + pkg
.oldver
;
52 // append @github_account to body
53 // only mention user on official gentoo-zh repo
54 github_accounts
= getGithubAccount(pkg
.name
);
55 if (typeof github_accounts
== "object") {
56 // multiple accounts example:
57 // github_account = ["st0nie", "peeweep"]
59 for (let github_account
of github_accounts
) {
60 body
+= repo_is_gentoo_zh_official
61 ? " @" + github_account
62 : " " + github_account
64 } else if (typeof github_accounts
== "string") {
65 // single account example:
66 // github_account = "peeweep"
67 body
+= repo_is_gentoo_zh_official
68 ? "\nCC: @" + github_accounts
69 : "\nCC: " + github_accounts
72 // if body still empty, convert to null
73 // because github rest api response's issue body is null, they should be same
78 // search issues by titlePrefix
81 // repo_name = "microcai/gentoo-zh";
82 searchQuery
= `repo:${repo_name} is:issue label:nvchecker in:title ${titlePrefix}`;
86 const searchIssues
= await github
.rest
.search
.issuesAndPullRequests({
91 response
= searchIssues
.data
.items
;
93 issuesData
= issuesData
.concat(response
);
94 if (response
.length
< 100) {
98 core
.warning(`failed to search issues with title: ${searchQuery}`);
104 // search existed in issues
105 for (let issueData
of issuesData
) {
106 // if titlePrefix matched
108 issueData
.title
.length
>= titlePrefix
.length
109 ? issueData
.title
.substring(0, titlePrefix
.length
) == titlePrefix
112 // titlePrefix matched;
113 if (issueData
.body
== body
&& issueData
.title
== title
) {
114 // if body and title all matched, goto next loop
117 // if body or title not matched
118 if (issueData
.state
== "open") {
119 // if state is open, edit it, then goto next loop
120 // if (!repo_is_gentoo_zh_official) {
121 // // only update on official gentoo-zh repo
124 const issueUpdate
= await github
.rest
.issues
.update({
125 owner
: context
.repo
.owner
,
126 repo
: context
.repo
.repo
,
127 issue_number
: issueData
.number
,
131 console
.log("Edit issue on %s", issueUpdate
.data
.html_url
);
134 // if state is clsoe,create new
142 const issuesCreate
= await github
.rest
.issues
.create({
143 owner
: context
.repo
.owner
,
144 repo
: context
.repo
.repo
,
147 labels
: ["nvchecker"],
149 console
.log("Created issue on %s", issuesCreate
.data
.html_url
);
151 core
.warning(`failed to create issues with title: ${title}`);