Skip to content

Allow editing flashcards after creation #275

Allow editing flashcards after creation

Allow editing flashcards after creation #275

Workflow file for this run

name: Auto Tag and Assign "In Progress"
on:
push:
# Trigger on pushes to any branch
branches:
- '**'
jobs:
tag-and-assign-in-progress:
runs-on: ubuntu-latest
env:
label: "In Progress 🚧"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Auto Tag and Assign Issues with "In Progress"
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const label = process.env.label;
// Function to add label to an issue
async function addLabel(owner, repo, issue_number) {
try {
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: [label],
});
console.log(`Added label "${label}" to issue #${issue_number}`);
} catch (error) {
console.error(`Failed to add label to issue #${issue_number}:`, error);
}
}
// Function to assign a user to an issue
async function assignUser(owner, repo, issue_number, username) {
try {
await github.rest.issues.addAssignees({
owner,
repo,
issue_number,
assignees: [username],
});
console.log(`Assigned @${username} to issue #${issue_number}`);
} catch (error) {
console.error(`Failed to assign @${username} to issue #${issue_number}:`, error);
}
}
// Function to check if a number corresponds to an issue (not a PR)
async function isIssue(owner, repo, issue_number) {
try {
const { data } = await github.rest.issues.get({
owner,
repo,
issue_number,
});
return !data.pull_request; // If pull_request field is absent, it's an issue
} catch (error) {
console.error(`Failed to fetch issue #${issue_number}:`, error);
return false;
}
}
// Regex to find issue references like #123
const issueRegex = /(?:^|\s)#(\d+)/g;
// Set to store unique issue numbers
const issues = new Set();
// Set to store unique usernames to assign
const assignees = new Set();
if (context.eventName === 'push') {
const commits = context.payload.commits;
for (const commit of commits) {
let message = commit.message;
// Identify merge commits
const isMergeCommit = message.startsWith('Merge pull request');
if (isMergeCommit) {
console.log(`Skipping merge commit: ${commit.id}`);
continue; // Skip merge commits
}
let matches;
while ((matches = issueRegex.exec(message)) !== null) {
const issueNum = parseInt(matches[1]);
issues.add(issueNum);
console.log(`Found issue reference #${issueNum} in commit message: "${message}"`);
// Add commit author as assignee
if (commit.author && commit.author.username) {
assignees.add(commit.author.username);
}
}
}
}
if (issues.size === 0) {
console.log('No issue references found.');
return;
}
const owner = context.repo.owner;
const repo = context.repo.repo;
for (const issue_number of issues) {
const isIssueResult = await isIssue(owner, repo, issue_number);
if (isIssueResult) {
await addLabel(owner, repo, issue_number);
for (const username of assignees) {
await assignUser(owner, repo, issue_number, username);
}
} else {
console.log(`Reference #${issue_number} is a Pull Request. Skipping.`);
}
}