mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
chore(ci): fixed release notification action; (#6064)
This commit is contained in:
+3
-3
@@ -27,7 +27,7 @@ export default class GithubAPI {
|
|||||||
return (await this.axios.post(`/issues/${issue}/comments`, {body})).data;
|
return (await this.axios.post(`/issues/${issue}/comments`, {body})).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getComments(issue, {desc = false, per_page= 100, page = 1}) {
|
async getComments(issue, {desc = false, per_page= 100, page = 1} = {}) {
|
||||||
return (await this.axios.get(`/issues/${issue}/comments`, {params: {direction: desc ? 'desc' : 'asc', per_page, page}})).data;
|
return (await this.axios.get(`/issues/${issue}/comments`, {params: {direction: desc ? 'desc' : 'asc', per_page, page}})).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,11 +40,11 @@ export default class GithubAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async appendLabels(issue, labels) {
|
async appendLabels(issue, labels) {
|
||||||
return (await this.axios.post(`issues/${issue}/labels`, {labels})).data;
|
return (await this.axios.post(`/issues/${issue}/labels`, {labels})).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUser(user) {
|
async getUser(user) {
|
||||||
return (await this.axios.get(`users/${user}`)).data;
|
return (await githubAxios.get(`/users/${user}`)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async isCollaborator(user) {
|
async isCollaborator(user) {
|
||||||
|
|||||||
+23
-2
@@ -4,9 +4,19 @@ import Handlebars from "handlebars";
|
|||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
import {colorize} from "./helpers/colorize.js";
|
import {colorize} from "./helpers/colorize.js";
|
||||||
import {getReleaseInfo} from "./contributors.js";
|
import {getReleaseInfo} from "./contributors.js";
|
||||||
|
import path from "path";
|
||||||
|
import {fileURLToPath} from "url";
|
||||||
|
|
||||||
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
const NOTIFY_PR_TEMPLATE = path.resolve(__dirname, '../templates/pr_published.hbs');
|
||||||
|
|
||||||
const normalizeTag = (tag) => tag ? 'v' + tag.replace(/^v/, '') : '';
|
const normalizeTag = (tag) => tag ? 'v' + tag.replace(/^v/, '') : '';
|
||||||
|
|
||||||
|
const GITHUB_BOT_LOGIN = 'github-actions[bot]';
|
||||||
|
|
||||||
|
const skipCollaboratorPRs = true;
|
||||||
|
|
||||||
class RepoBot {
|
class RepoBot {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
const {
|
const {
|
||||||
@@ -15,7 +25,7 @@ class RepoBot {
|
|||||||
} = options || {};
|
} = options || {};
|
||||||
|
|
||||||
this.templates = Object.assign({
|
this.templates = Object.assign({
|
||||||
published: '../templates/pr_published.hbs'
|
published: NOTIFY_PR_TEMPLATE
|
||||||
}, templates);
|
}, templates);
|
||||||
|
|
||||||
this.github = api || new GithubAPI(owner, repo);
|
this.github = api || new GithubAPI(owner, repo);
|
||||||
@@ -53,7 +63,18 @@ class RepoBot {
|
|||||||
|
|
||||||
await this.github.appendLabels(id, [tag]);
|
await this.github.appendLabels(id, [tag]);
|
||||||
|
|
||||||
if (isBot || labels.find(({name}) => name === 'automated pr') || (await this.github.isCollaborator(login))) {
|
if (isBot || labels.find(({name}) => name === 'automated pr') || (skipCollaboratorPRs && await this.github.isCollaborator(login))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const comments = await this.github.getComments(id, {desc: true});
|
||||||
|
|
||||||
|
const comment = comments.find(
|
||||||
|
({body, user}) => user.login === GITHUB_BOT_LOGIN && body.indexOf('published in') >= 0
|
||||||
|
)
|
||||||
|
|
||||||
|
if (comment) {
|
||||||
|
console.log(colorize()`Release comment [${comment.html_url}] already exists in #${pr.id}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -1,11 +1,19 @@
|
|||||||
import axios from '../index.js';
|
import axios from '../index.js';
|
||||||
|
import {colorize} from "./helpers/colorize.js";
|
||||||
|
|
||||||
const {GITHUB_TOKEN} = process.env;
|
const {GITHUB_TOKEN} = process.env;
|
||||||
|
|
||||||
GITHUB_TOKEN ? console.log(`[GITHUB_TOKEN OK]`) : console.warn(`[GITHUB_TOKEN is not defined]`);
|
GITHUB_TOKEN ? console.log(`[GITHUB_TOKEN OK]`) : console.warn(`[GITHUB_TOKEN is not defined]`);
|
||||||
|
|
||||||
|
const defaultTransform = axios.defaults.transformRequest;
|
||||||
|
|
||||||
export default axios.create({
|
export default axios.create({
|
||||||
|
transformRequest: [defaultTransform[0], function (data) {
|
||||||
|
console.log(colorize()`[${this.method.toUpperCase()}] Request [${new URL(axios.getUri(this)).pathname}]`);
|
||||||
|
return data;
|
||||||
|
}],
|
||||||
|
baseURL: 'https://api.github.com/',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: GITHUB_TOKEN ? `token ${GITHUB_TOKEN}` : null
|
Authorization: GITHUB_TOKEN ? `token ${GITHUB_TOKEN}` : null
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
Hello, @{{ author.login }}! This PR has been published in [{{ release.tag }}]({{ release.url }}) release. Thank you for your contribution ❤️!
|
Hi, @{{ author.login }}! This PR has been published in [{{ release.tag }}]({{ release.url }}) release. Thank you for your contribution ❤️!
|
||||||
|
|||||||
Reference in New Issue
Block a user