Skip to content

Commit

Permalink
Merge pull request #1071 from Anjaliavv51/assign-workflow
Browse files Browse the repository at this point in the history
✨[Feature Request]: Automatic assign
  • Loading branch information
varshith257 authored Jul 31, 2024
2 parents abd17e2 + f8a9531 commit fcd947a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- ISSUE & PR TITLE SHOULD BE SAME-->
## Description
<!--Please include a brief description of the changes or features added-->
<!--Please include a brief description of the changes-->


## Related Issues
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/assignlabel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Assign Issue to Creator

on:
issue_comment:
types: [created]

jobs:
assign-issue:
runs-on: ubuntu-latest
if: contains(github.event.comment.body, '/assign')
steps:
- name: Check commenter permissions
id: check-permissions
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo;
const commenter = context.payload.comment.user.login;
const { data: repoPermission } = await github.rest.repos.getCollaboratorPermissionLevel({
owner,
repo,
username: commenter,
});
const allowedPermissions = ['admin', 'maintain', 'write'];
const hasPermission = allowedPermissions.includes(repoPermission.permission);
return hasPermission;
- name: Assign issue to creator
if: steps.check-permissions.outputs.result == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const { data: issue } = await github.rest.issues.get({
owner,
repo,
issue_number,
});
const creator = issue.user.login;
await github.rest.issues.addAssignees({
owner,
repo,
issue_number,
assignees: [creator],
});
console.log(`Assigned issue #${issue_number} to creator ${creator}`);
62 changes: 32 additions & 30 deletions .github/workflows/auto-label-pr.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@

name: Auto Label PR
name: Auto Label PRs

on:
pull_request:
types: [opened, reopened, edited,synchronize]
types: [opened, edited]

jobs:
label_pr:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Label PR
- uses: actions/labeler@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml

- name: Add GSSOC label
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pr = context.payload.pull_request;
// Add gssoc label to all PRs
await github.rest.issues.addLabels({
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: ['gssoc']
});
})
- name: Add additional labels based on title
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const title = context.payload.pull_request.title.toLowerCase();
const labelsToAdd = [];
const prBody = pr.body ? pr.body.toLowerCase() : '';
const prTitle = pr.title.toLowerCase();
if (title.includes('documentation')) {
labelsToAdd.push('documentation');
}
if (title.includes('feature')) {
labelsToAdd.push('feature');
}
if (title.includes('bug')) {
labelsToAdd.push('bug');
}
const addLabel = async (label) => {
await github.rest.issues.addLabels({
if (labelsToAdd.length > 0) {
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [label]
labels: labelsToAdd
});
};
if (prBody.includes('documentation') || prTitle.includes('doc') || prBody.includes('readme')) {
await addLabel('documentation');
}
if (prBody.includes('feature') || prBody.includes('enhancement') || prTitle.includes('add') || prTitle.includes('implement')) {
await addLabel('enhancement');
}
if (prBody.includes('bug') || prBody.includes('fix') || prTitle.includes('fix') || prTitle.includes('resolve')) {
await addLabel('bug');
}

0 comments on commit fcd947a

Please sign in to comment.