Skip to content

Commit

Permalink
Don't trigger PR limit reminder on PRs that are ignored (#3596)
Browse files Browse the repository at this point in the history
* Don't trigger PR limit reminder on PRs that are ignored

* Use all "valid PR" conditions for checking whether to alert

* Fix variable casing

* Rename valid to relevant

* Include escape hatch for if current PR is not relevant

* Make variable names more appropriate
  • Loading branch information
AetherUnbound authored Jan 22, 2024
1 parent fb0fdd9 commit 0f2fdc3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pr_limit_reminders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
outputs:
pr_count: ${{ steps.count-prs.outputs.pr_count }}
slack_id: ${{ steps.count-prs.outputs.slack_id }}
should_alert: ${{ steps.count-prs.outputs.should_alert }}
steps:
- uses: actions/checkout@v4
- uses: actions/github-script@v6
Expand All @@ -26,7 +27,7 @@ jobs:
send_message:
needs: analyze-user-prs
name: Send Slack message
if: ${{ needs.analyze-user-prs.outputs.pr_count >= 3 }}
if: needs.analyze-user-prs.outputs.pr_count >= 3
runs-on: ubuntu-latest
env:
pr_count: ${{ needs.analyze-user-prs.outputs.pr_count }}
Expand Down
53 changes: 30 additions & 23 deletions automations/js/src/count_user_reviewable_prs.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,46 @@ query ($repoOwner: String!, $repo: String!, $cursor: String) {
'🟥 priority: critical',
]
const [owner, repo] = GITHUB_REPOSITORY.split('/')
const isRelevantPrFromGraphql = (pr) =>
pr.author.login === context.actor &&
!pr.isDraft &&
!pr.labels.nodes.some((label) => ignoredLabels.includes(label.name))
const isRelevantPrFromContext = (pr) =>
!pr.draft && !pr.labels.some((label) => ignoredLabels.includes(label.name))

try {
let hasNextPage = true
let cursor = null
let reviewablePRs = []
let reviewablePrs = []
const pullRequest = context.payload.pull_request
const result = {
pr_count: 0,
slack_id: slackID,
}

while (hasNextPage) {
const result = await github.graphql(GET_PULL_REQUESTS, {
repoOwner: owner,
repo: repo,
cursor: cursor,
})
// Check that this pull request is relevant, otherwise skip the action entirely
if (isRelevantPrFromContext(pullRequest)) {
while (hasNextPage) {
const result = await github.graphql(GET_PULL_REQUESTS, {
repoOwner: owner,
repo: repo,
cursor: cursor,
})

const { nodes, pageInfo } = result.repository.pullRequests
const validPRs = nodes.filter(
(pr) =>
pr.author.login === context.actor &&
!pr.isDraft &&
!pr.labels.nodes.some((label) => ignoredLabels.includes(label.name))
)
reviewablePRs.push(...validPRs)
const { nodes, pageInfo } = result.repository.pullRequests
const relevantPrs = nodes.filter(isRelevantPrFromGraphql)
reviewablePrs.push(...relevantPrs)

if (pageInfo.hasNextPage) {
cursor = pageInfo.endCursor
} else {
hasNextPage = false
if (pageInfo.hasNextPage) {
cursor = pageInfo.endCursor
} else {
hasNextPage = false
}
}
}

const result = {
pr_count: reviewablePRs.length,
slack_id: slackID,
result.pr_count = reviewablePrs.length
}

core.info(`Current user has ${result.pr_count} PR(s).`)
core.setOutput('pr_count', result.pr_count)
core.setOutput('slack_id', result.slack_id)
Expand Down

0 comments on commit 0f2fdc3

Please sign in to comment.