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

Updated assign_issues.yml #29068

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
122 changes: 105 additions & 17 deletions .github/workflows/assign_issue.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,114 @@
name: Take Issue
name: Handle Issue Assignments

on:
issue_comment:
types:
- created
- edited
types: [created]
issues:
types: [assigned, unassigned]

permissions: read-all
permissions:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move the "permissions" section under "jobs" section, like described here? It will allow us to comply with our security requirements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, it is better to leave permissions: read-all by default for all jobs and set write permissions for particular jobs only

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sure

issues: write
repository-projects: write

jobs:
take-issue:
name: Take issue
handle-issue:
runs-on: ubuntu-latest
permissions:
issues: write
timeout-minutes: 10
if: ${{ github.repository_owner == 'openvinotoolkit' }}
steps:
- name: take an issue
uses: bdougie/take-action@1439165ac45a7461c2d89a59952cd7d941964b87 # v1.6.1
- name: Process issue
uses: actions/github-script@v6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uses: actions/github-script@v6
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 #v6

with:
message: Thank you for looking into this issue! Please let us know if you have any questions or require any help.
issueCurrentlyAssignedMessage: Thanks for being interested in this issue. It looks like this ticket is already assigned to a contributor. Please communicate with the assigned contributor to confirm the status of the issue.
trigger: .take
token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script is not small one, maybe it is better to wrap it into the custom JS action?
And it could be merged with #28491

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is an alternative to #28491, only one should be merged.

const LABEL = "good first issue";
const COLUMNS = {
todo: "Contributors needed",
inProgress: "Assigned",
done: "Closed"
};

const issue = context.payload.issue;

async function getProjectId() {
try {
const projects = await github.rest.projects.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo
});
const project = projects.data.find(p => p.name === "Good first issues");
if (!project) throw new Error("Project not found");
return project.id;
} catch (err) {
console.log("Error fetching project ID:", err);
throw err;
}
}

async function moveIssue(columnName) {
if (!issue.labels?.some(l => l.name.toLowerCase() === LABEL)) {
console.log(`Issue #${issue.number} - not a good first issue, skipping`);
return;
}

try {
const PROJECT_ID = await getProjectId();
const columns = await github.rest.projects.listColumns({ project_id: PROJECT_ID });
const column = columns.data.find(c => c.name === columnName);
if (!column) throw new Error(`Can't find column ${columnName}`);

const cards = await github.rest.projects.listCards({ column_id: column.id });
const existingCard = cards.data.find(c => c.content_url.endsWith(`/issues/${issue.number}`));

if (existingCard) {
await github.rest.projects.moveCard({
card_id: existingCard.id,
position: "top",
column_id: column.id
});
} else {
await github.rest.projects.createCard({
column_id: column.id,
content_id: issue.id,
content_type: "Issue"
});
}

console.log(`Updated issue #${issue.number} to ${columnName}`);
} catch (err) {
console.log(`Error updating issue #${issue.number}:`, err);
throw err;
}
}

if (context.payload.comment) {
const comment = context.payload.comment.body.trim();
const user = context.payload.comment.user.login;

if (comment === ".take") {
await moveIssue(COLUMNS.inProgress);
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
assignees: [user]
});
}

if (comment === ".release") {
const assignees = issue.assignees.map(a => a.login).filter(a => a !== user);
await github.rest.issues.removeAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
assignees: [user]
});

if (assignees.length === 0) {
await moveIssue(COLUMNS.todo);
}
}
}

if (context.payload.action === "assigned" || context.payload.action === "unassigned") {
const hasAssignee = issue.assignees?.length > 0;
await moveIssue(hasAssignee ? COLUMNS.inProgress : COLUMNS.todo);
}