From 2f3683ce674ff52f27ed50bfdc734d9311810c0b Mon Sep 17 00:00:00 2001 From: Hardik Goyal <135348086+HardikGoyal2003@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:13:01 +0530 Subject: [PATCH] Fix #20381 : Added Github Action for developer Onboarding leads (#20683) * Added developer notification * Made minor changes * Added intermediate env variable * removed name * Added env approach * Added exception in linters --- .../developer_onboarding_notification.yml | 70 +++++++++++++++++++ scripts/linters/other_files_linter.py | 3 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/developer_onboarding_notification.yml diff --git a/.github/workflows/developer_onboarding_notification.yml b/.github/workflows/developer_onboarding_notification.yml new file mode 100644 index 0000000000000..a14d4d9a95112 --- /dev/null +++ b/.github/workflows/developer_onboarding_notification.yml @@ -0,0 +1,70 @@ +name: PR Merge Comment + +on: + pull_request_target: + types: [closed] + +permissions: write-all + +jobs: + comment-on-merge: + if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set environment variables + env: + AUTHOR: ${{ github.event.pull_request.user.login }} + REPO: ${{ github.event.repository.name }} + OWNER: ${{ github.event.repository.owner.login }} + run: | + echo "AUTHOR=${AUTHOR}" >> $GITHUB_ENV + echo "REPO=${REPO}" >> $GITHUB_ENV + echo "OWNER=${OWNER}" >> $GITHUB_ENV + + - name: Count merged PRs + id: count-prs + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const author = process.env.AUTHOR; + const repo = process.env.REPO; + const owner = process.env.OWNER; + const { data } = await github.rest.search.issuesAndPullRequests({ + q: `repo:${owner}/${repo} type:pr state:closed author:${author}` + }); + const prCount = data.items.filter(pr => pr.pull_request.merged_at).length; + core.exportVariable('PR_COUNT', prCount); + + - name: Comment on the PR + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prCount = parseInt(process.env.PR_COUNT); + const author = process.env.AUTHOR; + const mention = 'HardikGoyal2003'; // Update this if the mention needs to change + const prNumber = context.payload.pull_request.number; + + let message; + if (prCount === 1) { + message = `Thanks @${author}, and congratulations on your first PR to Oppia! 🎉 🥳\n` + + `Feel free to take up a second issue if you'd like to help out more!\n\n` + + `Developer onboarding lead : @${mention}`; + } else if (prCount === 2) { + message = `@${author} Congratulations on your second merged PR to Oppia! 🎉 🥳\n` + + `Since you've merged two PRs, you might be eligible to join the Oppia dev team as a collaborator. If you'd like to do that, please fill in [this form](https://forms.gle/NxPjimCMqsSTNUgu5). Thanks!\n\n` + + `Developer onboarding lead : @${mention}`; + } + + if (prCount === 1 || prCount === 2) { + await github.rest.issues.createComment({ + owner: process.env.OWNER, + repo: process.env.REPO, + issue_number: prNumber, + body: message + }); + } diff --git a/scripts/linters/other_files_linter.py b/scripts/linters/other_files_linter.py index 80b39733ffbfa..7bb6edde33f3d 100644 --- a/scripts/linters/other_files_linter.py +++ b/scripts/linters/other_files_linter.py @@ -73,7 +73,8 @@ class ThirdPartyLibDict(TypedDict): 'develop_commit_notification.yml', 'pending-review-notification.yml', 'revert-web-wiki-updates.yml', - 'frontend_tests.yml' + 'frontend_tests.yml', + 'developer_onboarding_notification.yml' ) JOBS_EXEMPT_FROM_MERGE_REQUIREMENT: Final = [ 'check_test_suites_to_run'