Skip to content

Commit bfa9c3d

Browse files
committed
Build: updating PRs with internal prerelease @semantic-release plugin
1 parent c4b2ada commit bfa9c3d

File tree

5 files changed

+66
-38
lines changed

5 files changed

+66
-38
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"babel-jest": "^26.6.3",
7474
"commitlint-config-eslint": "^1.0.0",
7575
"conventional-changelog-eslint": "^3.0.9",
76+
"debug": "^4.3.1",
7677
"eslint": "^7.14.0",
7778
"eslint-plugin-jest": "^24.1.3",
7879
"eslint-plugin-jest-dom": "^3.3.0",

release.config.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,22 @@ const mainConfig = {
7676
const branchConfig = {
7777
plugins: [
7878
...basePlugins,
79-
[
80-
//require.resolve("./release/github-prerelease"),
81-
"@semantic-release/github",
82-
{
83-
successComment: `
79+
{
80+
name: "github-prerelease",
81+
path: "./release",
82+
successComment: `
8483
This PR is part of this prerelease version for testing: \${nextRelease.version}
8584
8685
You can test it by using:
8786
\`\`\`bash
8887
npm install scriptloader-component@\${nextRelease.version}
8988
\`\`\`
9089
`,
91-
releasedLabels: [],
92-
},
93-
],
90+
labels: false,
91+
releasedLabels: false,
92+
assets: "*.tgz",
93+
debug: true,
94+
},
9495
],
9596
};
9697

release/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require("./create-github-prerelease");
2+
module.exports = require("./github-prerelease");

release/success.js

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
const { isNil, uniqBy, flatten } = require("lodash");
22
const pFilter = require("p-filter");
33
const issueParser = require("issue-parser");
4+
const debug = require("debug")("semantic-release:github-prerelease");
45

5-
// this file will be copied two folders deeper
6-
const resolveConfig = require("./resolve-config");
7-
const getClient = require("./resolve-config");
8-
const parseGithubUrl = require("./parse-github-url");
9-
const getSearchQueries = require("./get-search-queries");
6+
const resolveConfig = require("@semantic-release/github/lib/resolve-config");
7+
const getClient = require("@semantic-release/github/lib/get-client");
8+
const parseGithubUrl = require("@semantic-release/github/lib/parse-github-url");
9+
const getSearchQueries = require("@semantic-release/github/lib/get-search-queries");
10+
11+
// these files will be copied two folders deeper
1012
const success = require("./new-success");
1113

14+
const ghGet = async (ghResult) => {
15+
const res = await ghResult;
16+
return (res && res.data) || res;
17+
};
18+
1219
module.exports = async (pluginConfig, context) => {
1320
const {
1421
options: { repositoryUrl },
@@ -22,15 +29,19 @@ module.exports = async (pluginConfig, context) => {
2229
proxy,
2330
successComment,
2431
} = resolveConfig(pluginConfig, context);
25-
const github = getClient({
26-
githubToken,
27-
githubUrl,
28-
githubApiPathPrefix,
29-
proxy,
30-
});
32+
const github = getClient(
33+
{
34+
githubToken,
35+
githubUrl,
36+
githubApiPathPrefix,
37+
proxy,
38+
},
39+
context
40+
);
41+
const { login } = await ghGet(github.users.getAuthenticated());
3142
const [owner, repo] = (
32-
await github.repos.get(parseGithubUrl(repositoryUrl))
33-
).data.full_name.split("/");
43+
await ghGet(github.repos.get(parseGithubUrl(repositoryUrl)))
44+
).full_name.split("/");
3445

3546
if (successComment === false) {
3647
logger.log("Skipping old comment deletion.");
@@ -42,20 +53,23 @@ module.exports = async (pluginConfig, context) => {
4253
const shas = commits.map(({ hash }) => hash);
4354

4455
const searchQueries = getSearchQueries(
45-
`repo:${owner}/${repo}+type:pr+is:merged`,
56+
`repo:${owner}/${repo}+type:pr+is:open`,
4657
shas
4758
).map(
48-
async (q) => (await github.search.issuesAndPullRequests({ q })).data.items
59+
async (q) =>
60+
(await ghGet(github.search.issuesAndPullRequests({ q }))).items
4961
);
5062

5163
const prs = await pFilter(
5264
uniqBy(flatten(await Promise.all(searchQueries)), "number"),
5365
async ({ number }) =>
5466
(
55-
await github.pulls.listCommits({ owner, repo, pull_number: number })
56-
).data.find(({ sha }) => shas.includes(sha)) ||
67+
await ghGet(
68+
github.pulls.listCommits({ owner, repo, pull_number: number })
69+
)
70+
).find(({ sha }) => shas.includes(sha)) ||
5771
shas.includes(
58-
(await github.pulls.get({ owner, repo, pull_number: number })).data
72+
(await ghGet(github.pulls.get({ owner, repo, pull_number: number })))
5973
.merge_commit_sha
6074
)
6175
);
@@ -77,23 +91,32 @@ module.exports = async (pluginConfig, context) => {
7791
: issues;
7892
}, []);
7993

94+
const allIssues = uniqBy([...prs, ...issues], "number");
8095
await Promise.all(
81-
uniqBy([...prs, ...issues], "number").map(async (issue) => {
96+
allIssues.map(async (issue) => {
8297
try {
8398
const comments = { owner, repo, issue_number: issue.number };
84-
const foundComments = (
85-
await github.issues.listComments(comments)
86-
).filter((comment) => comment.user.login === "im-pipeline-bot");
99+
const allComments = await ghGet(github.issues.listComments(comments));
100+
const targetComments = allComments.filter(
101+
(comment) => comment.user.login === login
102+
);
87103

88-
for (let c in foundComments) {
89-
await github.issues.deleteComment({
90-
owner,
91-
repo,
92-
comment_id: c.id,
93-
});
94-
logger.log("Removed comment %c from issue #%d", c.id, issue.number);
95-
}
104+
await Promise.all(
105+
targetComments.map(async (c) => {
106+
await github.issues.deleteComment({
107+
owner,
108+
repo,
109+
comment_id: c.id,
110+
});
111+
logger.log(
112+
"Removed comment %s from issue #%d",
113+
c.id,
114+
issue.number
115+
);
116+
})
117+
);
96118
} catch (error) {
119+
debug("got an error deleting a comment", error);
97120
if (error.status === 403) {
98121
logger.error(
99122
"Not allowed to delete a comment to the issue #%d.",

0 commit comments

Comments
 (0)