mirror of
https://gitea.com/Lydanne/pr-extract-issues.git
synced 2025-08-19 02:06:02 +08:00
wip
This commit is contained in:
35
README.md
35
README.md
@@ -1,42 +1,9 @@
|
|||||||
<p align="center">
|
# PR Extract Issues
|
||||||
<a href="">
|
|
||||||
<img width="140" src="https://avatars.githubusercontent.com/u/73879334?s=200&v=4" />
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h1 align="center">Action JavaScript Template</h1>
|
|
||||||
<div align="center">
|
|
||||||
A simple javascript template for rapid development of GitHub actions.
|
|
||||||
</div>
|
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/marketplace/actions/action-js-template)
|
[](https://github.com/marketplace/actions/action-js-template)
|
||||||
[](https://github.com/actions-cool/action-js-template/releases)
|
[](https://github.com/actions-cool/action-js-template/releases)
|
||||||
|
|
||||||
## 🚀 How to use?
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## 📒 Catalog Introduction
|
|
||||||
|
|
||||||
```
|
|
||||||
├── .github/workflows/ The CI for make sure it is packaged correctly
|
|
||||||
├── dist Package the generated Aciton execution code
|
|
||||||
├── src Component home directory
|
|
||||||
│ └── main.js Your code
|
|
||||||
└── action.yml Action config
|
|
||||||
```
|
|
||||||
|
|
||||||
The rest of the documents can be consulted by yourself.
|
|
||||||
|
|
||||||
## 🤖 Command introduction
|
|
||||||
|
|
||||||
| Name | Desc |
|
|
||||||
| -- | -- |
|
|
||||||
| package | action build for release |
|
|
||||||
| format | prettier write |
|
|
||||||
| format-check | prettier check |
|
|
||||||
|
|
||||||
## ⚡ Feedback
|
## ⚡ Feedback
|
||||||
|
|
||||||
You are very welcome to try it out and put forward your comments. You can use the following methods:
|
You are very welcome to try it out and put forward your comments. You can use the following methods:
|
||||||
|
21
action.yml
21
action.yml
@@ -1,22 +1,25 @@
|
|||||||
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions
|
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions
|
||||||
name: 'Action JS Template'
|
name: 'PR Extract Issues'
|
||||||
description: 'A simple javascript template for rapid development of GitHub actions.'
|
description: 'A GitHub Action help you extract issues from pr commit or title or body.'
|
||||||
author: 'xrkffgg'
|
author: 'xrkffgg'
|
||||||
|
|
||||||
branding:
|
|
||||||
# https://actions-cool.github.io/github-action-branding/
|
# https://actions-cool.github.io/github-action-branding/
|
||||||
icon: 'file'
|
branding:
|
||||||
color: 'blue'
|
icon: 'hard-drive'
|
||||||
|
color: 'white'
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
GITHUB_TOKEN:
|
token:
|
||||||
description: Secret GitHub API token to use for making API requests.
|
description: Secret GitHub API token to use for making API requests.
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
required: true
|
required: true
|
||||||
|
way:
|
||||||
|
description: The way to query issues.
|
||||||
|
required: true
|
||||||
|
|
||||||
#outputs:
|
outputs:
|
||||||
# result:
|
issues:
|
||||||
# description: action result
|
description: Get issues numbers.
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
|
5679
dist/index.js
vendored
5679
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "action-js-template",
|
"name": "pr-extract-issues",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "A javascript template for rapid development of GitHub actions.",
|
"description": "A GitHub Action help you extract issues from pr commit or title or body.",
|
||||||
"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"
|
||||||
},
|
},
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/actions-cool/action-js-template",
|
|
||||||
"branch": "main"
|
|
||||||
},
|
|
||||||
"author": "xrkffgg",
|
"author": "xrkffgg",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
61
src/main.js
61
src/main.js
@@ -1,17 +1,64 @@
|
|||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
const { Octokit } = require('@octokit/rest');
|
||||||
|
const github = require('@actions/github');
|
||||||
|
|
||||||
|
// **********************************************************
|
||||||
|
const token = core.getInput('token');
|
||||||
|
const octokit = new Octokit({ auth: `token ${token}` });
|
||||||
|
const context = github.context;
|
||||||
|
|
||||||
|
const outEventErr = `This Action only support "pull_request" "pull_request_target"!`;
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const ms = core.getInput('milliseconds');
|
const { owner, repo } = context.repo;
|
||||||
core.debug(`Waiting ${ms} milliseconds ...`); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
|
if (context.eventName === 'pull_request_target' || context.eventName === 'pull_request') {
|
||||||
|
const title = context.payload.pull_request.title;
|
||||||
|
const body = context.payload.pull_request.body;
|
||||||
|
const number = context.payload.pull_request.number;
|
||||||
|
|
||||||
core.debug(new Date().toTimeString());
|
let issues = [];
|
||||||
await new Promise(resolve => {
|
const way = core.getInput('way');
|
||||||
setTimeout(() => resolve('done!'), 10);
|
if (way === 'title') {
|
||||||
|
let arr = title.split('');
|
||||||
|
arr.forEach(it => {
|
||||||
|
if (it.startsWith('#')) {
|
||||||
|
issues.push(it.replace('#', ''));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
core.debug(new Date().toTimeString());
|
} else if (way === 'body') {
|
||||||
|
let arr = body.split('\n');
|
||||||
|
arr.forEach(it => {
|
||||||
|
if (it.startsWith('#')) {
|
||||||
|
issues.push(it.replace('#', ''));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (way === 'commit') {
|
||||||
|
const { data: commits } = await octokit.pulls.listCommits({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
pull_number: number,
|
||||||
|
// 一般不会超过 100 个 commit 吧,😌 不想分页了,暂时保留
|
||||||
|
per_page: 100,
|
||||||
|
});
|
||||||
|
commits.forEach(commit => {
|
||||||
|
let message = commit.commit.message;
|
||||||
|
let messageArr = message.split('');
|
||||||
|
messageArr.forEach(it => {
|
||||||
|
if (it.startsWith('#')) {
|
||||||
|
issues.push(it.replace('#', ''));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
core.setFailed('Wrong way!');
|
||||||
|
}
|
||||||
|
|
||||||
core.setOutput('time', new Date().toTimeString());
|
core.info(`[Action: Query Issues][${issues}]`);
|
||||||
|
core.setOutput('issues', issues);
|
||||||
|
} else {
|
||||||
|
core.setFailed(outEventErr);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user