Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/global-replicator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
uses: derberg/manage-files-in-multiple-repositories@beecbe897cf5ed7f3de5a791a3f2d70102fe7c25
with:
github_token: ${{ secrets.GH_TOKEN }}
patterns_to_include: .github/workflows/scripts,.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml,.github/workflows/add-good-first-issue-labels.yml,.github/workflows/automerge-for-humans-merging.yml,.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml,.github/workflows/automerge-orphans.yml,.github/workflows/automerge.yml,.github/workflows/autoupdate.yml,.github/workflows/help-command.yml,.github/workflows/issues-prs-notifications.yml,.github/workflows/lint-pr-title.yml,.github/workflows/notify-tsc-members-mention.yml,.github/workflows/stale-issues-prs.yml,.github/workflows/welcome-first-time-contrib.yml,.github/workflows/release-announcements.yml,.github/workflows/bounty-program-commands.yml,.github/workflows/please-take-a-look-command.yml,.github/workflows/update-pr.yml,.github/workflows/transfer-issue.yml
patterns_to_include: .github/workflows/scripts,.github/workflows/automerge-for-humans-add-ready-to-merge-or-do-not-merge-label.yml,.github/workflows/add-good-first-issue-labels.yml,.github/workflows/automerge-for-humans-merging.yml,.github/workflows/automerge-for-humans-remove-ready-to-merge-label-on-edit.yml,.github/workflows/automerge-orphans.yml,.github/workflows/automerge.yml,.github/workflows/autoupdate.yml,.github/workflows/help-command.yml,.github/workflows/issues-prs-notifications.yml,.github/workflows/lint-pr-title.yml,.github/workflows/notify-tsc-members-mention.yml,.github/workflows/stale-issues-prs.yml,.github/workflows/welcome-first-time-contrib.yml,.github/workflows/release-announcements.yml,.github/workflows/bounty-program-commands.yml,.github/workflows/please-take-a-look-command.yml,.github/workflows/update-pr.yml,.github/workflows/transfer-issue.yml,.github/workflows/issue-needs-approval.yml,.github/workflows/issue-approval-check.yml,.github/workflows/issue-approval-commands.yml,.github/workflows/pr-approval-check.yml
committer_username: asyncapi-bot
committer_email: [email protected]
commit_message: "ci: update of files from global .github repo"
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/issue-approval-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Issue Approval Check

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
check-unapproved-issues:
if: startsWith(github.repository, 'asyncapi/')
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const now = new Date();
const sevenDaysAgo = new Date(now - 7 * 24 * 60 * 60 * 1000);
const twentyOneDaysAgo = new Date(now - 21 * 24 * 60 * 60 * 1000);

const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'needs-approval',
per_page: 100
});

for (const issue of issues) {
if (issue.pull_request) continue;

const createdAt = new Date(issue.created_at);
const issueNumber = issue.number;

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
per_page: 100
});

const hasReminder = comments.some(c =>
c.body.includes('Reminder: This issue is still awaiting approval')
);

if (createdAt < twentyOneDaysAgo) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `This issue has been automatically closed because it was not approved by a maintainer within 21 days.\n\nThis doesn't mean your issue isn't valid! It may simply mean maintainers haven't had time to review it. Feel free to:\n- Reopen this issue with more context\n- Reach out on [Slack](https://asyncapi.com/slack-invite) for discussion\n\nThank you for your understanding! ❤️`
});

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

console.log(`Closed issue #${issueNumber} (no approval after 21 days)`);
}
else if (createdAt < sevenDaysAgo && !hasReminder) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `**Reminder:** This issue is still awaiting approval from a maintainer.\n\nIf a maintainer doesn't approve this issue within the next **14 days**, it will be automatically closed.\n\nMaintainers: Please comment \`/approve\` to approve this issue or \`/reject\` to reject it.`
});

console.log(`Posted reminder on issue #${issueNumber}`);
}
}

145 changes: 145 additions & 0 deletions .github/workflows/issue-approval-commands.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Issue Approval Commands

on:
issue_comment:
types: [created]

jobs:
handle-approval-command:
if: >
startsWith(github.repository, 'asyncapi/') &&
!github.event.issue.pull_request &&
github.event.issue.state != 'closed' &&
(
contains(github.event.comment.body, '/approve') ||
contains(github.event.comment.body, '/reject')
)
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const commentBody = context.payload.comment.body.trim();
const commenter = context.payload.comment.user.login;
const issueNumber = context.payload.issue.number;

const botsList = ['asyncapi-bot', 'dependabot[bot]', 'dependabot-preview[bot]', 'allcontributors[bot]', 'github-actions[bot]'];
if (botsList.includes(commenter)) {
console.log(`Skipping: ${commenter} is a bot`);
return;
}

const isApprove = commentBody === '/approve' || commentBody.startsWith('/approve ');
const isReject = commentBody === '/reject' || commentBody.startsWith('/reject ');

if (!isApprove && !isReject) {
return;
}

let permissionLevel = 'none';
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: commenter
});
permissionLevel = data.permission;
} catch (error) {
console.log(`Could not get permission level for ${commenter}: ${error.message}`);
}

if (!['admin', 'write'].includes(permissionLevel)) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `@${commenter} Only maintainers with write or admin permissions can use the \`/approve\` and \`/reject\` commands.`
});
return;
}

const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});

const labels = issue.labels.map(l => l.name);

if (isApprove) {
if (labels.includes('approved')) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `@${commenter} This issue is already approved. ✅`
});
return;
}

if (labels.includes('needs-approval')) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: 'needs-approval'
});
}

if (!labels.includes('approved')) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['approved']
});
}

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `This issue has been approved by @${commenter}! 🎉\n\nContributors are welcome to work on this issue. If you'd like to work on it, please comment below to get assigned.`
});

console.log(`Issue #${issueNumber} approved by ${commenter}`);
}

if (isReject) {
if (labels.includes('needs-approval')) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: 'needs-approval'
});
}

if (labels.includes('approved')) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: 'approved'
});
}

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `This issue has been rejected by @${commenter}.\n\nThis issue doesn't align with current project priorities or guidelines. If you believe this was closed in error, feel free to reopen it with additional context.`
});

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

console.log(`Issue #${issueNumber} rejected and closed by ${commenter}`);
}

63 changes: 63 additions & 0 deletions .github/workflows/issue-needs-approval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Issue Needs Approval

on:
issues:
types: [opened, reopened]

jobs:
add-needs-approval:
if: startsWith(github.repository, 'asyncapi/')
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const botsList = ['asyncapi-bot', 'dependabot[bot]', 'dependabot-preview[bot]', 'allcontributors[bot]', 'github-actions[bot]'];
const issueAuthor = context.payload.issue.user.login;

if (botsList.includes(issueAuthor)) {
console.log(`Skipping: ${issueAuthor} is a bot`);
return;
}

let permissionLevel = 'none';
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: issueAuthor
});
permissionLevel = data.permission;
} catch (error) {
console.log(`Could not get permission level for ${issueAuthor}: ${error.message}`);
}

if (['admin', 'write'].includes(permissionLevel)) {
console.log(`Skipping: ${issueAuthor} is a maintainer (${permissionLevel})`);
return;
}

const issueNumber = context.payload.issue.number;
const action = context.payload.action;

await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['needs-approval']
});

const message = action === 'reopened'
? `This issue has been reopened and requires maintainer approval again.\n\nMaintainers can approve this issue by commenting \`/approve\` or reject it by commenting \`/reject\`.\n\nIf no approval is given within **21 days**, this issue will be automatically closed.\n\nThank you for your patience! ❤️`
: `Thank you for opening this issue! 🎉\n\nThis issue requires approval from a maintainer before work can begin. Maintainers can approve this issue by commenting \`/approve\` or reject it by commenting \`/reject\`.\n\n**Timeline:**\n- If not approved within **7 days**, a reminder will be posted\n- If not approved within **21 days**, this issue will be automatically closed\n\nPlease make sure your issue follows our [Contributing Guidelines](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md).\n\nThank you for your patience! ❤️`;

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: message
});

console.log(`Added needs-approval label and comment to issue #${issueNumber}`);

Loading