Yicong-Huang commented on code in PR #4551: URL: https://github.com/apache/texera/pull/4551#discussion_r3158186934
########## .github/workflows/auto-assign.yml: ########## @@ -0,0 +1,194 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Auto-assign +on: + pull_request_target: + types: [opened, reopened, ready_for_review, closed] Review Comment: only need open. ########## .github/workflows/auto-assign.yml: ########## @@ -0,0 +1,194 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Auto-assign +on: + pull_request_target: + types: [opened, reopened, ready_for_review, closed] + +permissions: + issues: write + pull-requests: write + +jobs: + # -------------------------------------------------------- + # Assign the PR author as the assignee on new/reopened PRs. + # New issues are intentionally left unassigned so they go + # through triage (see issue-triage.yml). + # -------------------------------------------------------- + assign-pr-author: + if: >- + github.event.action == 'opened' || + github.event.action == 'reopened' || + github.event.action == 'ready_for_review' + runs-on: ubuntu-latest + steps: + - name: Assign PR author + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const pr = context.payload.pull_request; + const issue_number = pr.number; + const author = pr.user && pr.user.login; + + if (!author) { + core.info(`PR #${issue_number} has no author login, skipping.`); + return; + } + + // PR authors that are bots (e.g. dependabot[bot]) cannot be assigned. + if (pr.user.type === 'Bot' || author.endsWith('[bot]')) { + core.info(`PR #${issue_number} authored by bot @${author}, skipping.`); + return; + } + + const existing = pr.assignees || []; + if (existing.length > 0) { + core.info( + `PR #${issue_number} already has ${existing.length} assignee(s), skipping.` + ); + return; + } + + try { + // PR assignees use the issues API (PRs are issues under the hood). + await github.rest.issues.addAssignees({ + owner, + repo, + issue_number, + assignees: [author], + }); + core.info(`Assigned @${author} to PR #${issue_number}.`); + } catch (e) { + core.warning( + `Failed to assign @${author} to PR #${issue_number}: ${e.message}` + ); + throw e; + } + + # -------------------------------------------------------- + # When a PR is merged, find the issues it closes (via the + # "Linked issues" relationship — closingIssuesReferences) + # and replace their assignees with the PR author so credit + # goes to whoever actually shipped the fix. + # -------------------------------------------------------- + credit-issue-on-pr-merge: + if: github.event.action == 'closed' && github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: Credit PR author on linked issues + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const pr = context.payload.pull_request; + const author = pr.user && pr.user.login; + + if (!author) { + core.info(`PR #${pr.number} has no author login, skipping.`); + return; + } + if (pr.user.type === 'Bot' || author.endsWith('[bot]')) { + core.info(`PR #${pr.number} authored by bot @${author}, skipping.`); + return; + } + + // Pull all issues this PR closes (handles "Closes #N", + // "Fixes #N", manual linking via the sidebar, etc.). + const linked = await github.graphql( + `query($owner: String!, $repo: String!, $pr: Int!) { + repository(owner: $owner, name: $repo) { + pullRequest(number: $pr) { + closingIssuesReferences(first: 50) { + nodes { + number + repository { nameWithOwner } + assignees(first: 20) { nodes { login } } + } + } + } + } + }`, + { owner, repo, pr: pr.number } + ); + + const nodes = + (linked.repository && + linked.repository.pullRequest && + linked.repository.pullRequest.closingIssuesReferences && + linked.repository.pullRequest.closingIssuesReferences.nodes) || []; + + if (nodes.length === 0) { + core.info(`PR #${pr.number} closes no linked issues, nothing to credit.`); + return; + } + + for (const issue of nodes) { + // Only touch issues in this repository. + if (issue.repository.nameWithOwner !== `${owner}/${repo}`) { + core.info( + `Skipping cross-repo linked issue ${issue.repository.nameWithOwner}#${issue.number}.` + ); + continue; + } + + const issue_number = issue.number; + const current = (issue.assignees.nodes || []).map(n => n.login); + const toRemove = current.filter(login => login !== author); + + // Remove existing assignees that aren't the PR author so the + // final assignee list is just [author] — gives sole credit Review Comment: Did you handle multiple authors? I think when an PR has multiple authors, we should assign all of them. But if someone only merges master and become an author, I don't know if we need to credit him/her. For insincere I can go on the PR list and click update PR for every Pr and get credited for all of them eventually. On the opposite we could also always only assign the first author only. You can decide. ########## .github/workflows/auto-assign.yml: ########## @@ -0,0 +1,194 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Auto-assign +on: + pull_request_target: + types: [opened, reopened, ready_for_review, closed] + +permissions: + issues: write + pull-requests: write + +jobs: + # -------------------------------------------------------- + # Assign the PR author as the assignee on new/reopened PRs. + # New issues are intentionally left unassigned so they go + # through triage (see issue-triage.yml). + # -------------------------------------------------------- + assign-pr-author: + if: >- + github.event.action == 'opened' || Review Comment: Only need open? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
