2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-14 18:42:33 +03:00

chore(ci): fixed release notification action; (#6063)

This commit is contained in:
Dmitriy Mozgovoy
2023-11-08 20:14:12 +02:00
committed by GitHub
parent f6d2cf9763
commit 7144f10dc5
7 changed files with 87 additions and 19 deletions
+18 -6
View File
@@ -5,7 +5,7 @@ import fs from "fs/promises";
import {colorize} from "./helpers/colorize.js";
import {getReleaseInfo} from "./contributors.js";
const normalizeTag = (tag) => tag.replace(/^v/, '');
const normalizeTag = (tag) => tag ? 'v' + tag.replace(/^v/, '') : '';
class RepoBot {
constructor(options) {
@@ -29,7 +29,17 @@ class RepoBot {
}
async notifyPRPublished(id, tag) {
const pr = await this.github.getPR(id);
let pr;
try {
pr = await this.github.getPR(id);
} catch (err) {
if(err.response?.status === 404) {
throw new Error(`PR #${id} not found (404)`);
}
throw err;
}
tag = normalizeTag(tag);
@@ -41,7 +51,7 @@ class RepoBot {
return false
}
await this.github.appendLabels(id, ['v' + tag]);
await this.github.appendLabels(id, [tag]);
if (isBot || labels.find(({name}) => name === 'automated pr') || (await this.github.isCollaborator(login))) {
return false;
@@ -56,7 +66,7 @@ class RepoBot {
author,
release: {
tag,
url: `https://github.com/${this.owner}/${this.repo}/releases/tag/v${tag}`
url: `https://github.com/${this.owner}/${this.repo}/releases/tag/${tag}`
}
});
@@ -64,6 +74,8 @@ class RepoBot {
}
async notifyPublishedPRs(tag) {
tag = normalizeTag(tag);
const release = await getReleaseInfo(tag);
if (!release) {
@@ -80,9 +92,9 @@ class RepoBot {
try {
console.log(colorize()`${i++}) Notify PR #${pr.id}`)
const result = await this.notifyPRPublished(pr.id, tag);
console.log(result ? 'OK' : 'Skipped');
console.log('✔️', result ? 'Label, comment' : 'Label');
} catch (err) {
console.warn(colorize('green', 'red')` Failed notify PR ${pr.id}: ${err.message}`);
console.warn(colorize('green', 'red')` Failed notify PR ${pr.id}: ${err.message}`);
}
}
}