1 async function getSearchIssuesResult(github, repo_name, titleSearchKeyword, page_number) {
2 // repo_name = "microcai/gentoo-zh";
3 searchQuery = `repo:${repo_name} is:issue label:nvchecker in:title ${titleSearchKeyword}`;
4 const searchIssues = await github.rest.search.issuesAndPullRequests({
9 return searchIssues.data.items;
12 function getGithubAccount(package) {
13 var toml = require("toml");
14 var fs = require("fs");
15 var tomlFileContent = fs.readFileSync(
16 ".github/workflows/overlay.toml",
20 github_account = toml.parse(tomlFileContent)[package]["github_account"];
22 return github_account;
25 module.exports = async ({ github, context, core }) => {
26 // hardcode gentoo-zh official repo name
27 var gentoo_zh_official_repo_name = "microcai/gentoo-zh";
28 var repo_name = process.env.GITHUB_REPOSITORY;
29 var repo_is_gentoo_zh_official = repo_name == gentoo_zh_official_repo_name;
31 let pkgs = JSON.parse(process.env.pkgs);
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") {
38 titlePrefix = "[nvchecker] " + pkg.name + " can be bump to ";
39 title = titlePrefix + pkg.newver;
41 if (pkg.oldver != null) {
42 body += "oldver: " + pkg.oldver;
45 // append @github_account to body
46 // only mention user on official gentoo-zh repo
47 github_accounts = getGithubAccount(pkg.name);
48 if (typeof github_accounts == "object") {
49 // multiple accounts example:
50 // github_account = ["st0nie", "peeweep"]
52 for (let github_account of github_accounts) {
53 body += repo_is_gentoo_zh_official
54 ? " @" + github_account
55 : " " + github_account
57 } else if (typeof github_accounts == "string") {
58 // single account example:
59 // github_account = "peeweep"
60 body += repo_is_gentoo_zh_official
61 ? "\nCC: @" + github_accounts
62 : "\nCC: " + github_accounts
65 // if body still empty, convert to null
66 // because github rest api response's issue body is null, they should be same
71 // search issues by titlePrefix
77 const response = await getSearchIssuesResult(
80 titleSearchKeyword = titlePrefix,
83 issuesData = issuesData.concat(response);
84 if (response.length < 100) {
88 core.warning(`Waring ${error}, action may still succeed though`);
93 // search existed in issues
94 for (let issueData of issuesData) {
95 // if titlePrefix matched
97 issueData.title.length >= titlePrefix.length
98 ? issueData.title.substring(0, titlePrefix.length) == titlePrefix
101 // titlePrefix matched;
102 if (issueData.body == body && issueData.title == title) {
103 // if body and title all matched, goto next loop
106 // if body or title not matched
107 if (issueData.state == "open") {
108 // if state is open, edit it, then goto next loop
109 // if (!repo_is_gentoo_zh_official) {
110 // // only update on official gentoo-zh repo
113 const issueUpdate = await github.rest.issues.update({
114 owner: context.repo.owner,
115 repo: context.repo.repo,
116 issue_number: issueData.number,
120 console.log("Edit issue on %s", issueUpdate.data.html_url);
123 // if state is clsoe,create new
131 const issuesCreate = await github.rest.issues.create({
132 owner: context.repo.owner,
133 repo: context.repo.repo,
136 labels: ["nvchecker"],
138 console.log("Created issue on %s", issuesCreate.data.html_url);
140 core.warning(`Waring ${error}, action may still succeed though`);