diff --git a/.github/workflows/auto_assign.yml b/.github/workflows/auto_assign.yml new file mode 100644 index 0000000000..11a2e0ee38 --- /dev/null +++ b/.github/workflows/auto_assign.yml @@ -0,0 +1,88 @@ +on: + issue_comment: + types: [created] + +permissions: + issues: write + models: read + +jobs: + auto-assign: + runs-on: ubuntu-latest + steps: + - name: Check if requesting assignment + uses: actions/ai-inference@v1 + id: check-request + with: + prompt: | + Does this comment ask to be assigned to the issue? + Respond with only "yes" or "no". + + Comment: ${{ github.event.comment.body }} + model: openai/gpt-4o-mini + + - name: Handle assignment + if: steps.check-request.outputs.response == 'yes' + uses: actions/github-script@v7 + with: + script: | + // Check if the issue is already assigned + const issue = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + if (issue.data.assignees.length > 0) { + // Issue is already assigned to someone else + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: "This issue has already been assigned. Please find another issue to work on: https://github.com/commons-app/apps-android-commons/issues?q=is%3Aissue%20state%3Aopen%20type%3ABug%20no%3Aassignee%20-label%3A%22low%20priority%22%20-label%3Adebated%20-label%3Aupstream" + }); + return; + } + + // Check commenter's existing assignments + const assignedIssues = await github.rest.issues.listForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + assignee: context.actor, + state: 'open' + }); + + const pullRequests = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + creator: context.actor, + state: 'open' + }); + + // No assigned issues - safe to assign + if (assignedIssues.data.length === 0) { + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + assignees: [context.actor] + }); + } + // Has assigned issues but no PRs - ask them to finish first + else if (assignedIssues.data.length > 0 && pullRequests.data.length === 0) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: "Please finish your previous assignment before you request to work on another" + }); + } + // Has assigned issues WITH PRs - they're making progress, assign them + else { + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + assignees: [context.actor] + }); + } \ No newline at end of file diff --git a/.github/workflows/pull_request_unrelated_changes.yml b/.github/workflows/pull_request_unrelated_changes.yml new file mode 100644 index 0000000000..5f8f123a07 --- /dev/null +++ b/.github/workflows/pull_request_unrelated_changes.yml @@ -0,0 +1,45 @@ +name: Check Pull Request Scope + +on: + pull_request: + types: [opened, synchronize] + +permissions: + pull-requests: write + models: read + +jobs: + check-scope: + runs-on: ubuntu-latest + steps: + # Use AI to detect if pull request mixes unrelated changes + - name: Analyse pull request changes + uses: actions/ai-inference@v1 + id: analyze + with: + prompt: | + Analyse this pull request to determine if it contains unrelated changes. + A pull request should modify only the code that really needs to be modified to solve the issue at hand. Changes unrelated to the issue at hand can be made in other pull requests. + + Examples of changes that are not acceptable: + * Fixing indentation or formatting in unrelated files or in unrelated parts of a file. + * Adding or removing unrelated comments. + + Pull Request Title: ${{ github.event.pull_request.title }} + Pull Request Description: ${{ github.event.pull_request.body }} + + Does this pull request appear to mix unrelated changes? Respond with only "yes" or "no". + model: openai/gpt-4o-mini + + # If unrelated changes detected, remind contributor of guidelines + - name: Comment if unrelated changes detected + if: steps.analyze.outputs.response == 'yes' + uses: actions/github-script@v7 + with: + script: | + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: "This pull request appears to contain unrelated changes. A pull request should modify only the code that really needs to be modified to solve the issue at hand. Please review [CONTRIBUTING.md](https://github.com/commons-app/apps-android-commons/blob/master/CONTRIBUTING.md) and consider splitting this into separate pull requests." + }); \ No newline at end of file diff --git a/.github/workflows/suggest_duplicate_bug.yml b/.github/workflows/suggest_duplicate_bug.yml new file mode 100644 index 0000000000..08bfe7671e --- /dev/null +++ b/.github/workflows/suggest_duplicate_bug.yml @@ -0,0 +1,24 @@ +name: Detect duplicate issues + +on: + issues: + types: [opened, reopened] + +permissions: + models: read + issues: write + +concurrency: + group: ${{ github.workflow }}-${{ github.event.issue.number }} + cancel-in-progress: true + +jobs: + continuous-triage-dedup: + if: ${{ github.event.issue.user.type != 'Bot' }} + runs-on: ubuntu-latest + steps: + - uses: pelikhan/action-genai-issue-dedup@v0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + # Optional tuning: + # labels: "auto" # compare within matching labels, or "bug,api" diff --git a/.github/workflows/welcome_new_contributors.yml b/.github/workflows/welcome_new_contributors.yml new file mode 100644 index 0000000000..c4e7c1096d --- /dev/null +++ b/.github/workflows/welcome_new_contributors.yml @@ -0,0 +1,41 @@ +name: Welcome New Contributors + +on: + pull_request: + types: [opened] + +permissions: + pull-requests: write + models: read + +jobs: + welcome: + runs-on: ubuntu-latest + if: github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' + steps: + - name: Generate welcome message + uses: actions/ai-inference@v1 + id: ai + with: + prompt: | + Write a friendly welcome message for a first-time contributor. Include: + 1. Thank them for their first PR + 2. Mention checking CONTRIBUTING.md + 3. Explain that after fixing 5 bugs, they can work on adding features + 4. Link to the welcome document: https://github.com/commons-app/commons-app-documentation/blob/master/android/Volunteers-welcome!.md + 5. Offer to help if they have questions + + Keep it brief and encouraging. + model: openai/gpt-4o-mini + + - name: Post welcome comment + uses: actions/github-script@v7 + with: + script: | + const message = `${{ steps.ai.outputs.response }}`; + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ github.event.pull_request.number }}, + body: message + }); \ No newline at end of file