mirror of
https://gitea.com/Lydanne/pr-extract-issues.git
synced 2025-08-22 19:49:18 +08:00
feat: support remove-labels
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.2.0
|
||||||
|
|
||||||
|
`2022.09.17`
|
||||||
|
|
||||||
|
- feat: support `remove-labels`.
|
||||||
|
|
||||||
## v1.1.0
|
## v1.1.0
|
||||||
|
|
||||||
`2021.03.17`
|
`2021.03.17`
|
||||||
|
@@ -42,6 +42,7 @@ jobs:
|
|||||||
| way | The way to query issues. Options: `title` `body` `commit` | string | ✔ |
|
| way | The way to query issues. Options: `title` `body` `commit` | string | ✔ |
|
||||||
| filter-label | Further filter issues through label | string | ✖ |
|
| filter-label | Further filter issues through label | string | ✖ |
|
||||||
| issues-labels | Extra labels on issues | string | ✖ |
|
| issues-labels | Extra labels on issues | string | ✖ |
|
||||||
|
| remove-labels | Remove labels on issues | string | ✖ |
|
||||||
| issues-comment | Extra comment on issues | string | ✖ |
|
| issues-comment | Extra comment on issues | string | ✖ |
|
||||||
| issues-close | Extra close issues | string | ✖ |
|
| issues-close | Extra close issues | string | ✖ |
|
||||||
|
|
||||||
|
@@ -22,6 +22,8 @@ inputs:
|
|||||||
description: Extra operations on issues
|
description: Extra operations on issues
|
||||||
issues-comment:
|
issues-comment:
|
||||||
description: Extra operations on issues
|
description: Extra operations on issues
|
||||||
|
remove-labels:
|
||||||
|
description: Will remove labels on issues
|
||||||
issues-close:
|
issues-close:
|
||||||
description: Extra operations on issues
|
description: Extra operations on issues
|
||||||
|
|
||||||
|
5953
dist/index.js
vendored
5953
dist/index.js
vendored
File diff suppressed because one or more lines are too long
15
package.json
15
package.json
@@ -1,16 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "pr-extract-issues",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "A GitHub Action help you extract issues from pr commit or title or body.",
|
"description": "A GitHub Action help you extract issues from pr commit or title or body.",
|
||||||
|
"license": "MIT",
|
||||||
|
"author": "xrkffgg",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"package": "ncc build",
|
"package": "ncc build",
|
||||||
"format": "prettier --write src/*.js",
|
"format": "prettier --write src/*.js",
|
||||||
"format-check": "prettier --check src/*.js"
|
"format-check": "prettier --check src/*.js",
|
||||||
|
"pub": "sh -e ./scripts/pub.sh"
|
||||||
},
|
},
|
||||||
"author": "xrkffgg",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/github": "^4.0.0",
|
"@actions/github": "^4.0.0",
|
||||||
@@ -20,6 +19,10 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@umijs/fabric": "^2.5.6",
|
"@umijs/fabric": "^2.5.6",
|
||||||
"@vercel/ncc": "^0.27.0",
|
"@vercel/ncc": "^0.27.0",
|
||||||
"prettier": "^2.2.1"
|
"chalk": "^4.1.2",
|
||||||
|
"new-github-release-url": "^1.0.0",
|
||||||
|
"open": "^7.3.0",
|
||||||
|
"prettier": "^2.2.1",
|
||||||
|
"simple-git": "^2.46.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
scripts/check-commit.js
Executable file
23
scripts/check-commit.js
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
const chalk = require('chalk');
|
||||||
|
const simpleGit = require('simple-git/promise');
|
||||||
|
|
||||||
|
const cwd = process.cwd();
|
||||||
|
const git = simpleGit(cwd);
|
||||||
|
|
||||||
|
async function checkCommit({ files }) {
|
||||||
|
if (files.length) {
|
||||||
|
console.log(chalk.yellow('🙄 You forgot something to commit.'));
|
||||||
|
files.forEach(({ path: filePath }) => {
|
||||||
|
console.log(' -', chalk.red(filePath));
|
||||||
|
});
|
||||||
|
console.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
const status = await git.status();
|
||||||
|
await checkCommit(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
9
scripts/const.js
Normal file
9
scripts/const.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
const CHANGELOG_NAME = 'CHANGELOG.md';
|
||||||
|
const user = 'actions-cool';
|
||||||
|
const repo = 'pr-extract-issues';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
CHANGELOG_NAME,
|
||||||
|
user,
|
||||||
|
repo,
|
||||||
|
};
|
14
scripts/pub.sh
Normal file
14
scripts/pub.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
echo "[TEST] check format"
|
||||||
|
npm run format-check
|
||||||
|
|
||||||
|
echo "[TEST] test package"
|
||||||
|
npm run package
|
||||||
|
|
||||||
|
echo "[TEST] test commit"
|
||||||
|
npm run check-commit
|
||||||
|
|
||||||
|
echo "[Action] do tag"
|
||||||
|
npm run tag
|
||||||
|
|
||||||
|
echo "[Action] do release"
|
||||||
|
npm run release
|
55
scripts/release.js
Normal file
55
scripts/release.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
const chalk = require('chalk');
|
||||||
|
const open = require('open');
|
||||||
|
const newGithubReleaseUrl = require('new-github-release-url');
|
||||||
|
const { readFileSync } = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const {
|
||||||
|
CHANGELOG_NAME,
|
||||||
|
user,
|
||||||
|
repo
|
||||||
|
} = require('./const');
|
||||||
|
|
||||||
|
let tag = '';
|
||||||
|
|
||||||
|
function getChangelog(content) {
|
||||||
|
const lines = content.split('\n');
|
||||||
|
const changeLog = [];
|
||||||
|
const pin = /^## /;
|
||||||
|
let begin = false;
|
||||||
|
for (let i = 0; i < lines.length; i += 1) {
|
||||||
|
const line = lines[i];
|
||||||
|
if (begin && pin.test(line)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (begin && line) {
|
||||||
|
changeLog.push(line);
|
||||||
|
}
|
||||||
|
if (!begin) {
|
||||||
|
begin = pin.test(line);
|
||||||
|
if (begin) {
|
||||||
|
tag = line.substring(3, line.length).trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changeLog.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
const changelogPath = path.join(__dirname, '..', CHANGELOG_NAME);
|
||||||
|
const changelog = readFileSync(changelogPath, 'utf-8');
|
||||||
|
|
||||||
|
const body = getChangelog(changelog);
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
const url = newGithubReleaseUrl({
|
||||||
|
user,
|
||||||
|
repo,
|
||||||
|
tag,
|
||||||
|
body: body,
|
||||||
|
});
|
||||||
|
|
||||||
|
await open(url);
|
||||||
|
|
||||||
|
console.log(chalk.yellow('🚀 Please check tag and changelog. Then click publish!'));
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
70
scripts/tag.js
Normal file
70
scripts/tag.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
const chalk = require('chalk');
|
||||||
|
const simpleGit = require('simple-git/promise');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const { readFileSync } = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const { CHANGELOG_NAME } = require('./const');
|
||||||
|
|
||||||
|
const CHANGELOG_PATH = path.join(__dirname, '..', CHANGELOG_NAME);
|
||||||
|
const CHANGELOG = readFileSync(CHANGELOG_PATH, 'utf-8');
|
||||||
|
|
||||||
|
const cwd = process.cwd();
|
||||||
|
const git = simpleGit(cwd);
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
execSync(`git pull`);
|
||||||
|
|
||||||
|
const data = await git.tags();
|
||||||
|
const tags = data.all;
|
||||||
|
let tag = tags.reverse()[0];
|
||||||
|
console.log(chalk.green(`[Git Query] tag: ${tag}`));
|
||||||
|
|
||||||
|
const tagChangelog = getChangelogTag(CHANGELOG);
|
||||||
|
if (tagChangelog && tag != tagChangelog) {
|
||||||
|
console.log(chalk.yellow(`[Git Action] Push new ${tagChangelog} tag!`));
|
||||||
|
execSync(`git tag ${tagChangelog}`);
|
||||||
|
execSync(`git push origin ${tagChangelog}:${tagChangelog}`);
|
||||||
|
execSync(`git pull`);
|
||||||
|
tag = tagChangelog;
|
||||||
|
} else {
|
||||||
|
console.log(chalk.yellow('🙄 Please add new release changelog first.'));
|
||||||
|
console.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tagSimple = tag.startsWith('v') ? tag.substring(0, 2) : tag.substring(0, 1);
|
||||||
|
console.log(chalk.green(`[Git Query] tagSimple: ${tagSimple}`));
|
||||||
|
|
||||||
|
if (tags.includes(tagSimple)) {
|
||||||
|
console.log(chalk.yellow(`[Git Action] Delete ${tagSimple} tag`));
|
||||||
|
execSync(`git push origin :refs/tags/${tagSimple}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(chalk.yellow(`[Git Action] Add new simple ${tagSimple} tag`));
|
||||||
|
execSync(`git push origin ${tag}:${tagSimple}`);
|
||||||
|
console.log(chalk.green('🎉 Done!'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getChangelogTag(content) {
|
||||||
|
const lines = content.split('\n');
|
||||||
|
const pin = /^## /;
|
||||||
|
let begin = false;
|
||||||
|
let tag = '';
|
||||||
|
|
||||||
|
for (let i = 0; i < lines.length; i += 1) {
|
||||||
|
const line = lines[i];
|
||||||
|
if (begin && pin.test(line)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!begin) {
|
||||||
|
begin = pin.test(line);
|
||||||
|
if (begin) {
|
||||||
|
tag = line.substring(3, line.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tag.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
16
src/main.js
16
src/main.js
@@ -1,7 +1,7 @@
|
|||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
const { Octokit } = require('@octokit/rest');
|
const { Octokit } = require('@octokit/rest');
|
||||||
const github = require('@actions/github');
|
const github = require('@actions/github');
|
||||||
const { dealStringToArr } = require('actions-util');
|
const { dealStringToArr, THANKS } = require('actions-util');
|
||||||
|
|
||||||
// **********************************************************
|
// **********************************************************
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
@@ -78,6 +78,8 @@ async function run() {
|
|||||||
core.setOutput('issues', issues);
|
core.setOutput('issues', issues);
|
||||||
|
|
||||||
const labels = core.getInput('issues-labels');
|
const labels = core.getInput('issues-labels');
|
||||||
|
const removeLabelsString = core.getInput('remove-labels');
|
||||||
|
const removeLabels = dealStringToArr(removeLabelsString);
|
||||||
const comment = core.getInput('issues-comment');
|
const comment = core.getInput('issues-comment');
|
||||||
const close = core.getInput('issues-close');
|
const close = core.getInput('issues-close');
|
||||||
|
|
||||||
@@ -95,6 +97,17 @@ async function run() {
|
|||||||
});
|
});
|
||||||
core.info(`Actions: [add-labels][${issue}][${labels}] success!`);
|
core.info(`Actions: [add-labels][${issue}][${labels}] success!`);
|
||||||
}
|
}
|
||||||
|
if (removeLabels && removeLabels.length) {
|
||||||
|
for (const label of removeLabels) {
|
||||||
|
await octokit.issues.removeLabel({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
issue_number: issue,
|
||||||
|
name: label,
|
||||||
|
});
|
||||||
|
core.info(`Actions: [remove-label][${issue}][${label}] success!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (comment) {
|
if (comment) {
|
||||||
const body = comment.replace('${number}', `#${issue}`);
|
const body = comment.replace('${number}', `#${issue}`);
|
||||||
await octokit.issues.createComment({
|
await octokit.issues.createComment({
|
||||||
@@ -118,6 +131,7 @@ async function run() {
|
|||||||
} else {
|
} else {
|
||||||
core.setFailed(outEventErr);
|
core.setFailed(outEventErr);
|
||||||
}
|
}
|
||||||
|
core.info(THANKS);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user