Skip to content

Commit

Permalink
[Chore] Add Github Actions to add label on issue and PR (#297)
Browse files Browse the repository at this point in the history
Signed-off-by: yandongxiao <[email protected]>
  • Loading branch information
yandongxiao authored Nov 2, 2023
1 parent 9d7ef19 commit 9d2349a
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 27 deletions.
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'bug'
assignees: ''

---

## Describe the bug

A clear and concise description of what the bug is.

## To Reproduce

Steps to reproduce the behavior:

## Expected behavior

A clear and concise description of what you expected to happen.

## Please complete the following information

- Operator Version: [e.g. v1.8.5]
- Chart Name: [e.g. kube-starrocks]
- Chart Version [e.g. v1.8.5]
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/documentation_issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Documentation
about: Report an issue related to documentation
title: ''
labels: 'documentation'
assignees: ''

---

## Describe the issue with documentation

A clear and concise description of what the issue is.

## Page link

If applicable, add the link to the page where the issue occurs.

## Suggested change

Describe what changes you suggest to improve the documentation.

## Additional context

Add any other context or screenshots about the documentation issue here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/enhancement_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Enhancement request
about: Propose an enhancement for this project
title: ''
labels: 'enhancement'
assignees: ''

---

## Describe the current behavior

A clear and concise description of the current behavior.

## Describe the enhancement

A clear and concise description of what you want to improve.

## Additional context

Add any other context or screenshots about the enhancement here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 'feature'
assignees: ''

---

## Describe the problem

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

## Describe the solution you'd like

A clear and concise description of what you want to happen.

## Additional context

Add any other context or screenshots about the enhancement here.
4 changes: 0 additions & 4 deletions .github/pr-labeler.yml

This file was deleted.

5 changes: 1 addition & 4 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ categories:
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: '🧰 Maintenance'
labels:
- 'chore'
- 'refactor'
- 'doc'
- 'documentation'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/add-comment-on-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Add Comment Action
on:
pull_request:
types: [closed]
permissions:
issues: write
pull-requests: write
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
comment:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Comment on PR
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const prComment = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: 'Thank you for your contribution!'
};
await github.rest.issues.createComment(prComment);
2 changes: 1 addition & 1 deletion .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI PIPELINE
name: UNIT TEST ACTION

on:
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: golangci-lint
name: Golangci-lint Action
on:
push:
branches:
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/label-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Label Issue Action
on:
issues:
types:
- reopened
- opened
permissions:
issues: write
jobs:
label_issues:
runs-on: ubuntu-latest
steps:
- name: Label issue
uses: actions/github-script@v6
with:
script: |
const issueTitle = context.payload.issue.title.toLowerCase();
const labelsToAdd = [];
if (issueTitle.includes('bug')) {
labelsToAdd.push('bug');
}
if (issueTitle.includes('feature')) {
labelsToAdd.push('feature');
}
if (issueTitle.includes('enhancement')) {
labelsToAdd.push('enhancement');
}
if (issueTitle.includes('documentation')) {
labelsToAdd.push('documentation');
}
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labelsToAdd
});
}
51 changes: 51 additions & 0 deletions .github/workflows/label-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Label PR Action
on:
pull_request:
types: [opened, reopened]

permissions:
issues: write
pull-requests: write
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
labeler:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Label PR based on commit messages
uses: actions/github-script@v5
with:
github-token: ${{ secrets.PAT }}
script: |
const { owner, repo, number: pull_number } = context.issue;
const { data: commits } = await github.rest.pulls.listCommits({ owner, repo, pull_number });
const labels = new Set();
for (const { commit } of commits) {
const message = commit.message.toLowerCase();
if (message.includes('feature')) {
labels.add('feature');
}
if (message.includes('enhancement')) {
labels.add('enhancement');
}
if (message.includes('bugfix')) {
labels.add('bugfix');
}
if (message.includes('chore')) {
labels.add('chore');
}
if (message.includes('documentation')) {
labels.add('documentation');
}
}
if (labels.size > 0) {
await github.rest.issues.addLabels({ owner, repo, issue_number: pull_number, labels: Array.from(labels) });
}
16 changes: 0 additions & 16 deletions .github/workflows/pr-labeler.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release Drafter
name: Release Drafter Action

on:
push:
Expand Down
17 changes: 17 additions & 0 deletions scripts/add-version-label-to-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# input parameters: a list of PR numbers and a version tag
# e.g. v1.8.5 1 2 3 4 5
VERSION_TAG=$1

# create label by gh
gh label create $VERSION_TAG

shift
PR_NUMBERS=("$@")

# iterate over the list of PR numbers
for PR_NUMBER in "${PR_NUMBERS[@]}"; do
# add a version label to each PR
gh pr edit $PR_NUMBER --add-label "$VERSION_TAG"
done

0 comments on commit 9d2349a

Please sign in to comment.