Skip to content

Commit

Permalink
Auto-assign issue user max concurrent issues enforced
Browse files Browse the repository at this point in the history
  • Loading branch information
csehatt741 committed Feb 19, 2025
1 parent bfd0137 commit 0da42b3
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 25 deletions.
115 changes: 96 additions & 19 deletions .github/workflows/auto-assign.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,79 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
env:
USER_MAX_CONCURRENT_ISSUE_COUNT: ${{ vars.USER_MAX_CONCURRENT_ISSUE_COUNT }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const comment = context.payload.comment;
const issue = context.issue;
const owner = "keyshade-xyz";
const repo = "keyshade";
const owner = 'keyshade-xyz';
const repo = 'keyshade';
const userMaxConcurrentIssueCount = process.env.USER_MAX_CONCURRENT_ISSUE_COUNT || 5;
async function listIssueEvents(issue) {
const allEvents = [];
let page = 1;
let hasNextPage = true;
while (hasNextPage) {
const issuesResponse = await github.rest.issues.listEventsForTimeline({
owner,
repo,
issue_number: issue.number,
per_page: 100,
page
});
allEvents.push(...issuesResponse.data);
hasNextPage = issuesResponse.headers.link && issuesResponse.headers.link.includes('rel="next"');
page++;
}
return allEvents;
}
async function listUserOpenIssuesWithoutActivePullRequest(user) {
const issuesWithoutActivePullRequest = [];
const { data: userOpenIssues } = await github.rest.issues.listForRepo({
owner,
repo,
state: 'open',
assignee: user.login,
per_page: 100
});
for (const issue of userOpenIssues) {
const events = await listIssueEvents(issue);
const userPullRequestIssues = events
.filter(event => event.event === 'cross-referenced')
.map(event => event.source.issue)
.filter(issue => issue && issue.pull_request && issue.user.login === comment.user.login);
if(userPullRequestIssues.length === 0) {
issuesWithoutActivePullRequest.push(issue);
continue;
}
for (const pullRequestIssue of userPullRequestIssues) {
const { data: pullRequest } = await github.rest.pulls.get({
owner,
repo,
pull_number: pullRequestIssue.number
});
if(pullRequest.draft) {
issuesWithoutActivePullRequest.push(issue);
break;
}
}
}
return issuesWithoutActivePullRequest;
}
async function updateProjectStatus(issueNumber) {
const projectsResponse = await github.rest.projects.listForRepo({
Expand All @@ -30,49 +96,60 @@ jobs:
per_page: 100,
});
const inProgressColumn = columnsResponse.data.find(column => column.name === "In Progress");
const inProgressColumn = columnsResponse.data.find(column => column.name === 'In Progress');
if (!inProgressColumn) continue;
const cardsResponse = await github.rest.projects.listCards({
column_id: inProgressColumn.id,
per_page: 100,
});
const issueCardExists = cardsResponse.data.some(card => card.content_id === issueNumber && card.content_type === "Issue");
const issueCardExists = cardsResponse.data.some(card => card.content_id === issueNumber && card.content_type === 'Issue');
if (!issueCardExists) {
await github.rest.projects.createCard({
column_id: inProgressColumn.id,
content_id: issueNumber,
content_type: "Issue",
content_type: 'Issue',
});
}
}
}
if (comment.body.startsWith('/attempt')) {
if (!issue.assignee) {
await github.rest.issues.addAssignees({
owner,
repo,
issue_number: issue.number,
assignees: [comment.user.login],
});
const userActiveIssues = await listUserOpenIssuesWithoutActivePullRequest(comment.user);
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `Assigned the issue to @${comment.user.login}!`,
});
if(userActiveIssues.length < userMaxConcurrentIssueCount) {
await github.rest.issues.addAssignees({
owner,
repo,
issue_number: issue.number,
assignees: [comment.user.login],
});
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `Assigned the issue to @${comment.user.login}!`,
});
await updateProjectStatus(issue.number);
await updateProjectStatus(issue.number);
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: '@${comment.user.login}, cannot concurrently work on more than ${userMaxConcurrentIssueCount} issues. Tag a maintainer if you need to take over.',
});
}
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: 'This issue is already assigned. Tag a maintainer if you need to take over.',
body: '@${comment.user.login}, this issue is already assigned. Tag a maintainer if you need to take over.',
});
}
}
6 changes: 3 additions & 3 deletions .github/workflows/issue-pr-reminder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = "keyshade-xyz";
const repo = "keyshade";
const owner = 'keyshade-xyz';
const repo = 'keyshade';
const createPrReminderEnabled = process.env.CREATE_PR_REMINDER_ENABLED || false;
const createPrReminderAfterDays = process.env.CREATE_PR_REMINDER_AFTER_DAYS || 2;
const createPrReminderAfterMilliseconds = createPrReminderAfterDays * 24 * 60 * 60 * 1000;
Expand All @@ -36,7 +36,7 @@ jobs:
const issuesResponse = await github.rest.issues.listForRepo({
owner,
repo,
state: "open",
state: 'open',
per_page: 100,
page
});
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/issue-unassign.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = "keyshade-xyz";
const repo = "keyshade";
const owner = 'keyshade-xyz';
const repo = 'keyshade';
const unassignIssueEnabled = process.env.UNASSIGN_ISSUE_ENABLED || false;
const unassignIssueAfterDays = process.env.CREATE_PR_REMINDER_AFTER_DAYS || 14;
const unassignIssueAfterMilliseconds = unassignIssueAfterDays * 24 * 60 * 60 * 1000;
Expand All @@ -36,7 +36,7 @@ jobs:
const issuesResponse = await github.rest.issues.listForRepo({
owner,
repo,
state: "open",
state: 'open',
per_page: 100,
page
});
Expand Down

0 comments on commit 0da42b3

Please sign in to comment.