Skip to content

Commit

Permalink
chore: 0.0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
RSS1102 committed Sep 20, 2024
1 parent 4d708ee commit 5e60f21
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/send-relevant-notifications-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout code repository
uses: vegetables-school/send-relevant-comment-action@v0.0.17
uses: vegetables-school/send-relevant-comment-action@v0.0.18
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
custom-comment: 'Hello, this is a custom comment'
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog


## v0.0.18

[compare changes](https://github.com/vegetables-school/send-relevant-comment-action/compare/v0.0.17...v0.0.18)

### 🏡 Chore

- 0.0.17 ([4d708ee](https://github.com/vegetables-school/send-relevant-comment-action/commit/4d708ee))

### ❤️ Contributors

- 阿Cai ([@RSS1102](http://github.com/RSS1102))

## v0.0.17

[compare changes](https://github.com/vegetables-school/send-relevant-comment-action/compare/v0.0.16...v0.0.17)
Expand Down
50 changes: 9 additions & 41 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@vegetables-school/send-relevant-comment-action",
"description": "Send comment of relevant issues and PR within the PR",
"license": "MIT",
"version": "0.0.17",
"version": "0.0.18",
"author": "vegetables-school",
"private": true,
"homepage": "https://github.com/vegetables-school/send-relevant-comment-action",
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { getPrRelate } from './pr_relate'
export async function run(): Promise<void> {
try {
const token = core.getInput('github-token')
core.info(`Token: ${token}`)
if (!token) {
core.setFailed('GitHub token not found, please provide github-token')
}
const octokit = github.getOctokit(token)
const context = github.context

Expand All @@ -21,7 +23,6 @@ export async function run(): Promise<void> {
const prRelateArr = await getPrRelate(octokit, context)

prRelateArr.forEach(async issueNumber => {
core.info(`Creating comment on issue #${issueNumber}`)
octokit.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
34 changes: 26 additions & 8 deletions src/pr_relate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,27 @@ export async function getPrRelate(
repo: context.repo.repo,
pull_number: context.issue.number
})
mergeDeduplicatedArr(prRelate, parsePrOwnRepoRelate(pullRequest.title))
mergeDeduplicatedArr(prRelate, parsePrOwnRepoRelate(pullRequest?.body))
prRelate = mergeDeduplicatedArr(
prRelate,
parsePrOwnRepoRelate(pullRequest.title)
)
prRelate = mergeDeduplicatedArr(
prRelate,
parsePrOwnRepoRelate(pullRequest?.body)
)

// 获取 pull request 的所有 commit 信息
const { data: listCommits } = await octokit.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
listCommits.forEach(commit =>
mergeDeduplicatedArr(prRelate, parsePrOwnRepoRelate(commit.commit.message))
listCommits.forEach(
commit =>
(prRelate = mergeDeduplicatedArr(
prRelate,
parsePrOwnRepoRelate(commit.commit.message)
))
)

// 获取 pull request 的所有 review comment 信息
Expand All @@ -56,8 +66,12 @@ export async function getPrRelate(
repo: context.repo.repo,
pull_number: context.issue.number
})
listReviewComments.forEach(reviewComment =>
mergeDeduplicatedArr(prRelate, parsePrOwnRepoRelate(reviewComment.body))
listReviewComments.forEach(
reviewComment =>
(prRelate = mergeDeduplicatedArr(
prRelate,
parsePrOwnRepoRelate(reviewComment.body)
))
)

// 获取 pull request 的所有 comment 信息
Expand All @@ -66,8 +80,12 @@ export async function getPrRelate(
repo: context.repo.repo,
issue_number: context.issue.number
})
listComments.forEach(comment =>
mergeDeduplicatedArr(prRelate, parsePrOwnRepoRelate(comment?.body))
listComments.forEach(
comment =>
(prRelate = mergeDeduplicatedArr(
prRelate,
parsePrOwnRepoRelate(comment?.body)
))
)

return prRelate
Expand Down
9 changes: 0 additions & 9 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import * as core from '@actions/core'
*/
export const parsePrOwnRepoRelate = (content?: string | null) => {
const regex = /#(\d+)/g
core.info(`content: ${content}`)
const matches = content?.match(regex)
core.info(Array.isArray(matches)?.toString())
core.info(`match: ${matches}`)
const result = matches
? matches.map(match => parseInt(match.replace('#', '')))
: []
core.info(`parsePrOwnRepoRelate: ${result}`)
return result
}

Expand All @@ -25,10 +21,5 @@ export const parsePrOwnRepoRelate = (content?: string | null) => {
*/

export const mergeDeduplicatedArr = (arr1: number[], arr2: number[]) => {
core.info(`arr1: ${arr1}`)
core.info(`arr2: ${arr2}`)
core.info(`arrs: ${[...arr1, ...arr2]}`)
core.info(`newSet: ${new Set([...arr1, ...arr2])}`)
core.info(`mergeDeduplicatedArr: ${Array.from(new Set([...arr1, ...arr2]))}`)
return Array.from(new Set([...arr1, ...arr2]))
}

0 comments on commit 5e60f21

Please sign in to comment.