mirror of
https://gitea.com/Lydanne/pr-extract-issues.git
synced 2025-08-17 09:16:01 +08:00
wip
This commit is contained in:
35
README.md
35
README.md
@@ -1,42 +1,9 @@
|
||||
<p align="center">
|
||||
<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>
|
||||
# PR Extract Issues
|
||||
|
||||

|
||||
[](https://github.com/marketplace/actions/action-js-template)
|
||||
[](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
|
||||
|
||||
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
|
||||
name: 'Action JS Template'
|
||||
description: 'A simple javascript template for rapid development of GitHub actions.'
|
||||
name: 'PR Extract Issues'
|
||||
description: 'A GitHub Action help you extract issues from pr commit or title or body.'
|
||||
author: 'xrkffgg'
|
||||
|
||||
branding:
|
||||
# https://actions-cool.github.io/github-action-branding/
|
||||
icon: 'file'
|
||||
color: 'blue'
|
||||
branding:
|
||||
icon: 'hard-drive'
|
||||
color: 'white'
|
||||
|
||||
inputs:
|
||||
GITHUB_TOKEN:
|
||||
token:
|
||||
description: Secret GitHub API token to use for making API requests.
|
||||
default: ${{ github.token }}
|
||||
required: true
|
||||
way:
|
||||
description: The way to query issues.
|
||||
required: true
|
||||
|
||||
#outputs:
|
||||
# result:
|
||||
# description: action result
|
||||
outputs:
|
||||
issues:
|
||||
description: Get issues numbers.
|
||||
|
||||
runs:
|
||||
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",
|
||||
"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",
|
||||
"scripts": {
|
||||
"package": "ncc build",
|
||||
"format": "prettier --write src/*.js",
|
||||
"format-check": "prettier --check src/*.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/actions-cool/action-js-template",
|
||||
"branch": "main"
|
||||
},
|
||||
"author": "xrkffgg",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
61
src/main.js
61
src/main.js
@@ -1,17 +1,64 @@
|
||||
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() {
|
||||
try {
|
||||
const ms = core.getInput('milliseconds');
|
||||
core.debug(`Waiting ${ms} milliseconds ...`); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
|
||||
const { owner, repo } = context.repo;
|
||||
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());
|
||||
await new Promise(resolve => {
|
||||
setTimeout(() => resolve('done!'), 10);
|
||||
let issues = [];
|
||||
const way = core.getInput('way');
|
||||
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) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user