Revert "Improve insights project automation" (#30878)

This reverts commit 1ab1fea198. On main
this step is failing on PRs.

Test Plan: CI is green
This commit is contained in:
Keegan Carruthers-Smith 2022-02-09 11:50:47 +02:00 committed by GitHub
parent 691f32ab8f
commit 984cac854f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 117 additions and 87 deletions

View File

@ -14,6 +14,33 @@ jobs:
# }
# }
# }' -F project=212
code-insights-board:
runs-on: ubuntu-latest
env:
PROJECT_ID: MDExOlByb2plY3ROZXh0MzI3Ng== # https://github.com/orgs/sourcegraph/projects/200
GITHUB_TOKEN: ${{ secrets.GH_PROJECTS_ACTION_TOKEN }}
steps:
- name: Get issue if relevant
if: ${{ contains(github.event.issue.labels.*.name, 'team/code-insights') }}
env:
NODE_ID: ${{ github.event.issue.node_id }}
run: echo 'NODE_ID='$NODE_ID >> $GITHUB_ENV
- name: Get pull request if relevant
if: ${{ contains(github.event.pull_request.labels.*.name, 'team/code-insights') }}
env:
NODE_ID: ${{ github.event.pull_request.node_id }}
run: echo 'NODE_ID='$NODE_ID >> $GITHUB_ENV
- name: Add to Code Insights board
if: ${{ env.NODE_ID != '' }}
run: |
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
mutation($project:ID!, $node_id:ID!) {
addProjectNextItem(input: {projectId: $project, contentId: $node_id}) {
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f node_id=$NODE_ID
code-intel-board:
runs-on: ubuntu-latest
env:

View File

@ -27,12 +27,13 @@ if (!$currentMilestone) {
return
}
Write-Information "Milestone ending today: $($currentMilestone.Title)"
$items = Get-GitHubBetaProjectItem -ProjectNodeId $ProjectNodeId | Where-Object { $_.Content -and $_.Content.Milestone }
$currentIterationItems = Find-GitHubIssue "org:sourcegraph milestone:`"$($currentMilestone.Title)`"" |
Get-GitHubBetaProjectItem |
Where-Object { $_.project.id -eq $ProjectNodeId }
Write-Information "$($items.Count) items in project"
$byIteration = $items | Group-Object -Property { $_.Content.Milestone.Title } -AsHashTable
$currentIterationItems = $byIteration[$currentMilestone.Title]
$finishedItems = $currentIterationItems | Where-Object { $_.Fields['Status'] -eq 'Done' }
$notSized = $currentIterationItems | Where-Object { !$_.Fields['Size 🔵'] }

View File

@ -2,13 +2,12 @@ name: Code Insights GitHub project automation
on:
issues:
types: [opened, closed, reopened, milestoned, labeled]
types: [closed, reopened]
pull_request:
types: [opened, edited, synchronize, ready_for_review, converted_to_draft]
jobs:
update-project-items:
name: Update project items
update-status:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@ -30,4 +29,4 @@ jobs:
$PSDefaultParameterValues['*GitHub*:Token'] = ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force
./.github/workflows/update-project-items.ps1 -ProjectNodeId 'MDExOlByb2plY3ROZXh0MzI3Ng==' -TeamLabel 'team/code-insights'
./.github/workflows/update-project-item-statuses.ps1 -ProjectNodeId 'MDExOlByb2plY3ROZXh0MzI3Ng==' -TeamLabel 'team/code-insights'

View File

@ -0,0 +1,82 @@
# Script to run as a GitHub action on issue and PR updates that will update the associated GitHub Beta project items.
[CmdletBinding()]
param(
# GitHub GraphQL Node ID of the GitHub Beta project
[Parameter(Mandatory)]
[string] $ProjectNodeId,
# The team/* label to filter issues/PRs by. All issues/PRs that don't have this label will be ignored.
[Parameter(Mandatory)]
[string] $TeamLabel
)
# Regex for extracting the "Closes #1234" pattern in GitHub PR descriptions
$fixIssuePattern = "(?:close|fixe?|resolve)(?:[sd])? (?:#|(?<owner>[\w_-]+)/(?<repo>[\w_-]+)#|https://github\.com/(?<owner>[\w_-]+)/(?<repo>[\w_-]+)/issues/)(?<number>\d+)"
switch ($github.event_name) {
'issues' {
# Find project item for the issue
# THIS DOES NOT SCALE AS THE PROJECT GETS LARGE, but it's the only way possible afaict.
# One way this is mitigated is that this request is streamed/paginated in order of most-recent-first,
# which means we can hope the issue is usually found in the first page(s).
if (-not ($github.event.issue.labels | Where-Object { $_.name -eq $TeamLabel })) {
Write-Information "Issue does not have $TeamLabel label, exiting."
return
}
$status = if ($github.event.action -eq 'closed') { 'Done' } else { 'In Progress' }
Get-GitHubBetaProjectItem -ProjectNodeId $ProjectNodeId |
Where-Object { $_.content -and $_.content.number -eq $github.event.issue.number } |
Select-Object -First 1 |
Set-GitHubBetaProjectItemField -FieldName 'Status' -Value $status |
ForEach-Object { Write-Information "Updated `"Status`" field of project item for $($_.content.url) to `"$status`"" }
}
'pull_request' {
$pr = $github.event.pull_request
# Ignore merged and closed PRs
if ($pr.state -ne 'open') {
return
}
$status = if ($pr.draft) { 'In Progress' } else { 'In Review' }
# Get fixed issues from the PR description
$fixedIssues = [regex]::Matches($pr.body, $fixIssuePattern, [Text.RegularExpressions.RegexOptions]::IgnoreCase) |
ForEach-Object {
$owner = if ($_.Groups['owner'].Success) { $_.Groups['owner'].Value } else { $github.event.repository.owner.login }
$repo = if ($_.Groups['repo'].Success) { $_.Groups['repo'].Value } else { $github.event.repository.name }
$number = $_.Groups['number'].Value
Get-GitHubIssue -Owner $owner -Repository $repo -Number $number
} |
Where-Object { $_.labels | Where-Object { $_.name -eq $TeamLabel } }
if (!$fixedIssues) {
Write-Information "No fixed issues with $TeamLabel label referenced from PR description, exiting."
return
}
Write-Information "Fixed issues:"
$fixedIssues | ForEach-Object HtmlUrl | Write-Information
# Find project items for the issues the PR references
Get-GitHubBetaProjectItem -ProjectNodeId $ProjectNodeId |
Where-Object {
$item = $_
$fixedIssues | Where-Object {
$item.content -and
$_.Number -eq $item.content.number -and
$_.Owner -eq $item.content.repository.owner.login -and
$_.RepositoryName -eq $item.content.repository.name
}
} |
Select-Object -First $fixedIssues.Count |
Set-GitHubBetaProjectItemField -FieldName 'Status' -Value $status |
ForEach-Object { Write-Information "Updated `"Status`" field of project item for $($_.content.url) to `"$status`"" }
}
}

View File

@ -1,79 +0,0 @@
# Script to run as a GitHub action on issue and PR updates that will update the associated GitHub Beta project items.
[CmdletBinding()]
param(
# GitHub GraphQL Node ID of the GitHub Beta project
[Parameter(Mandatory)]
[string] $ProjectNodeId,
# The team/* label to filter issues/PRs by. All issues/PRs that don't have this label will be ignored.
[Parameter(Mandatory)]
[string] $TeamLabel
)
# Regex for extracting the "Closes #1234" pattern in GitHub PR descriptions
$fixIssuePattern = "(?:close|fixe?|resolve)(?:[sd])? (?:#|(?<owner>[\w_-]+)/(?<repo>[\w_-]+)#|https://github\.com/(?<owner>[\w_-]+)/(?<repo>[\w_-]+)/issues/)(?<number>\d+)"
switch ($github.event_name) {
'issues' {
if (-not ($github.event.issue.labels | Where-Object { $_.name -eq $TeamLabel })) {
Write-Information "Issue does not have $TeamLabel label, exiting."
return
}
Write-Information "Issue was $($github.event.action)"
switch ($github.event.action) {
{'opened', 'labeled', 'milestoned'} {
# If team label was added or issue was just opened, add to project board
# If added to an iteration, update status and set "proposed by" to the event actor
# Idempotent, will return the item if already exists in the board (this is fine because we checked for the team label)
$item = $github.event.issue | Add-GitHubBetaProjectItem -ProjectNodeId $ProjectNodeId
if ($item.content.milestone) {
Write-Information "Updating issue as 'Proposed for iteration' by @$($github.event.sender.login)"
$item |
Set-GitHubBetaProjectItemField -Name 'Status' -Value 'Proposed for iteration' |
Set-GitHubBetaProjectItemField -Name 'Proposed by' -Value $github.event.sender.login
}
}
# If issue was closed or reopened, update Status column
{'closed', 'reopened'} {
$status = if ($github.event.action -eq 'closed') { 'Done' } else { 'In Progress' }
$github.event.issue |
# Idempotent, will return the item if already exists
Add-GitHubBetaProjectItem -ProjectNodeId $ProjectNodeId |
Set-GitHubBetaProjectItemField -ProjectNodeId $ProjectNodeId -FieldName 'Status' -Value $status |
ForEach-Object { Write-Information "Updated `"Status`" field of project item for $($_.content.url) to `"$status`"" }
}
}
}
'pull_request' {
$pr = $github.event.pull_request
# Ignore merged and closed PRs
if ($pr.state -ne 'open') {
return
}
$status = if ($pr.draft) { 'In Progress' } else { 'In Review' }
# Get fixed issues from the PR description
[regex]::Matches($pr.body, $fixIssuePattern, [Text.RegularExpressions.RegexOptions]::IgnoreCase) |
ForEach-Object {
$owner = if ($_.Groups['owner'].Success) { $_.Groups['owner'].Value } else { $github.event.repository.owner.login }
$repo = if ($_.Groups['repo'].Success) { $_.Groups['repo'].Value } else { $github.event.repository.name }
$number = $_.Groups['number'].Value
Write-Information "Found fixed issue $owner/$repo#$number"
Get-GitHubIssue -Owner $owner -Repository $repo -Number $number
} |
Where-Object { $_.labels | Where-Object { $_.name -eq $TeamLabel } } |
# Idempotent, will return the item if already exists
Add-GitHubBetaProjectItem -ProjectNodeId $ProjectNodeId |
Set-GitHubBetaProjectItemField -ProjectNodeId $ProjectNodeId -FieldName 'Status' -Value $status |
ForEach-Object { Write-Information "Updated `"Status`" field of project item for $($_.content.url) to `"$status`"" }
}
}