Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: auto-close issues #5177

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/auto-close-issue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Auto-close issues

on:
issues:
types: [opened]

jobs:
close_issue:
runs-on: ubuntu-latest
steps:
- name: Close issue if user does not have write or admin permissions
uses: actions/github-script@v6
with:
script: |
// Get the issue creator's username
const issueCreator = context.payload.issue.user.login;

// Check the user's permissions for the repository
const repoPermissions = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: issueCreator
});

const permission = repoPermissions.data.permission;

// If the user does not have write or admin permissions, leave a comment and close the issue
if (permission !== 'write' && permission !== 'admin') {
const commentBody = "Please see https://aquasecurity.github.io/trivy/latest/community/contribute/issue/";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: commentBody
});

await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
state: 'closed',
state_reason: 'not_planned'
});

console.log(`Issue #${context.payload.issue.number} closed because ${issueCreator} does not have sufficient permissions.`);
}
5 changes: 4 additions & 1 deletion docs/community/contribute/issue.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Issues
Thank you for taking interest in contributing to Trivy!

Trivy uses [GitHub Discussion](./discussion.md) for bug reports, feature requests, and questions.
Trivy uses [GitHub Discussion](./discussion.md) for bug reports, feature requests, and questions.

!!! warning
Issues created by non-maintainers will be immediately closed.
Loading