Skip to content

Commit 7009715

Browse files
chore(ci): fixed release notification action; (#6064)
1 parent 7144f10 commit 7009715

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

bin/GithubAPI.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class GithubAPI {
2727
return (await this.axios.post(`/issues/${issue}/comments`, {body})).data;
2828
}
2929

30-
async getComments(issue, {desc = false, per_page= 100, page = 1}) {
30+
async getComments(issue, {desc = false, per_page= 100, page = 1} = {}) {
3131
return (await this.axios.get(`/issues/${issue}/comments`, {params: {direction: desc ? 'desc' : 'asc', per_page, page}})).data;
3232
}
3333

@@ -40,11 +40,11 @@ export default class GithubAPI {
4040
}
4141

4242
async appendLabels(issue, labels) {
43-
return (await this.axios.post(`issues/${issue}/labels`, {labels})).data;
43+
return (await this.axios.post(`/issues/${issue}/labels`, {labels})).data;
4444
}
4545

4646
async getUser(user) {
47-
return (await this.axios.get(`users/${user}`)).data;
47+
return (await githubAxios.get(`/users/${user}`)).data;
4848
}
4949

5050
async isCollaborator(user) {

bin/RepoBot.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ import Handlebars from "handlebars";
44
import fs from "fs/promises";
55
import {colorize} from "./helpers/colorize.js";
66
import {getReleaseInfo} from "./contributors.js";
7+
import path from "path";
8+
import {fileURLToPath} from "url";
9+
10+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
11+
12+
const NOTIFY_PR_TEMPLATE = path.resolve(__dirname, '../templates/pr_published.hbs');
713

814
const normalizeTag = (tag) => tag ? 'v' + tag.replace(/^v/, '') : '';
915

16+
const GITHUB_BOT_LOGIN = 'github-actions[bot]';
17+
18+
const skipCollaboratorPRs = true;
19+
1020
class RepoBot {
1121
constructor(options) {
1222
const {
@@ -15,7 +25,7 @@ class RepoBot {
1525
} = options || {};
1626

1727
this.templates = Object.assign({
18-
published: '../templates/pr_published.hbs'
28+
published: NOTIFY_PR_TEMPLATE
1929
}, templates);
2030

2131
this.github = api || new GithubAPI(owner, repo);
@@ -53,7 +63,18 @@ class RepoBot {
5363

5464
await this.github.appendLabels(id, [tag]);
5565

56-
if (isBot || labels.find(({name}) => name === 'automated pr') || (await this.github.isCollaborator(login))) {
66+
if (isBot || labels.find(({name}) => name === 'automated pr') || (skipCollaboratorPRs && await this.github.isCollaborator(login))) {
67+
return false;
68+
}
69+
70+
const comments = await this.github.getComments(id, {desc: true});
71+
72+
const comment = comments.find(
73+
({body, user}) => user.login === GITHUB_BOT_LOGIN && body.indexOf('published in') >= 0
74+
)
75+
76+
if (comment) {
77+
console.log(colorize()`Release comment [${comment.html_url}] already exists in #${pr.id}`);
5778
return false;
5879
}
5980

bin/githubAxios.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import axios from '../index.js';
2+
import {colorize} from "./helpers/colorize.js";
23

34
const {GITHUB_TOKEN} = process.env;
45

56
GITHUB_TOKEN ? console.log(`[GITHUB_TOKEN OK]`) : console.warn(`[GITHUB_TOKEN is not defined]`);
67

8+
const defaultTransform = axios.defaults.transformRequest;
9+
710
export default axios.create({
11+
transformRequest: [defaultTransform[0], function (data) {
12+
console.log(colorize()`[${this.method.toUpperCase()}] Request [${new URL(axios.getUri(this)).pathname}]`);
13+
return data;
14+
}],
15+
baseURL: 'https://api.github.com/',
816
headers: {
917
Authorization: GITHUB_TOKEN ? `token ${GITHUB_TOKEN}` : null
1018
}
11-
})
19+
});

templates/pr_published.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Hello, @{{ author.login }}! This PR has been published in [{{ release.tag }}]({{ release.url }}) release. Thank you for your contribution ❤️!
1+
Hi, @{{ author.login }}! This PR has been published in [{{ release.tag }}]({{ release.url }}) release. Thank you for your contribution ❤️!

0 commit comments

Comments
 (0)