Skip to content

Commit 7009715

Browse files
authoredNov 8, 2023
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

+3-3
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

+23-2
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

+9-1
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

+1-1
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 ❤️!

1 commit comments

Comments
 (1)

PROECA commented on Oct 30, 2024

@PROECA

detruire jeu const axios = require('axios');
const ping = require('ping');
const dns = require('dns');
const readline = require('readline');
const gradient = require('gradient-string');
const chalk = require('chalk');

function displayTextWithEffect(text, delay = 50) {
const lines = text.split('\n');
lines.forEach((line, index) => {
setTimeout(() => console.log(line), index * delay);
});
}

const title =
██▓ ██▓███ ██▓ ███▄ █ █████▒ ▒█████
▓██▒▓██░ ██▒ ▓██▒ ██ ▀█ █ ▓██ ▒ ▒██▒ ██▒
▒██▒▓██░ ██▓▒ ▒██▒▓██ ▀█ ██▒▒████ ░ ▒██░ ██▒
░██░▒██▄█▓▒ ▒ ░██░▓██▒ ▐▌██▒░▓█▒ ░ ▒██ ██░
░██░▒██▒ ░ ░ ░██░▒██░ ▓██░░▒█░ ░ ████▓▒░
░▓ ▒▓▒░ ░ ░ ░▓ ░ ▒░ ▒ ▒ ▒ ░ ░ ▒░▒░▒░
▒ ░░▒ ░ ▒ ░░ ░░ ░ ▒░ ░ ░ ▒ ▒░
▒ ░░░ ▒ ░ ░ ░ ░ ░ ░ ░ ░ ░ ▒
░ ░ ░ ░ ░
;

const redGradient = gradient('red', 'darkred');

function displayTitle() {
console.clear();
displayTextWithEffect(redGradient(title), 50);
}

function askForIp() {
rl.question(chalk.red('\n[>] Adress IP Info : '), async (ipAddress) => {
await getIpInfo(ipAddress);
setTimeout(askForAnotherSearch, 5000); // Attendre 5 secondes avant de demander une nouvelle recherche
});
}

async function getIpInfo(ipAddress) {
const apiKey = 'bd8edfa317004261974006f2fd794e19';
const url = https://ipgeolocation.abstractapi.com/v1/?api_key=${apiKey}&ip_address=${ipAddress};

try {
    const response = await axios.get(url);
    const ipData = response.data;

NOUVEAU
[13:21]
const ipInfoText =
Adresse IP : ${ipData.ip_address}
Pays : ${ipData.country}
Code du pays : ${ipData.country_code}
Région : ${ipData.region}
Ville : ${ipData.city}
Latitude : ${ipData.latitude}
Longitude : ${ipData.longitude}
Code postal : ${ipData.postal_code}
Fuseau horaire : ${ipData.timezone.name}
UTC décalage : ${ipData.timezone.offset || 'N/A'}
ISP : ${ipData.connection.isp || 'N/A'}
Type de connexion : ${ipData.connection.connection_type}
;

    displayTextWithEffect(chalk.red(ipInfoText), 50);

    const pingRes = await ping.promise.probe(ipAddress);
    console.log(chalk.red(\nPing : ${pingRes.time} ms));

    dns.reverse(ipAddress, (err, hostnames) => {
        if (err) {
            console.error(chalk.red('Erreur DNS : '), err.message);
        } else {
            console.log(chalk.red(DNS : ${hostnames.join(', ')}));
        }
    });
} catch (error) {
    console.error(chalk.red('Erreur lors de la requête à l'API : '), error.message);
}

}

function askForAnotherSearch() {
console.log(); // Ajoute une ligne vide pour l'espacement
rl.question(chalk.red('Encore une recherche ? (yes/no) '), (answer) => {
if (answer.toLowerCase() === 'yes') {
displayTitle();
askForIp();
} else {
console.log(chalk.red('Au revoir!'));
rl.close();
}
});
}

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

displayTitle();
askForIp();
NOUVEAU

Envoyer un message dans #ipinfos

Please sign in to comment.