Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADO to GitHub - ADO Work Item links #1228

Open
WillEllis opened this issue Feb 21, 2024 · 8 comments
Open

ADO to GitHub - ADO Work Item links #1228

WillEllis opened this issue Feb 21, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@WillEllis
Copy link

Description

I've performed a trial run of migration from Azure DevOps Repos to GitHub and have a query around Work Item links. According to https://docs.github.com/en/migrations/using-github-enterprise-importer/migrating-from-azure-devops-to-github-enterprise-cloud/about-migrations-from-azure-devops-to-github-enterprise-cloud#data-that-is-migrated
Work items links on pull requests are migrated. This is a pretty key feature as we have many pull requests with the linked to many different work items with Azure DevOps Boards.

However when I ran the test work items ended up like this:
image
The pull request not found here is because ado2gh has disabled the ADO repo. But with the Work item links on PRs being migrated to me implies I should see GitHub PR links on this work item, like https://learn.microsoft.com/en-gb/azure/devops/boards/github/link-to-from-github?view=azure-devops#view-or-open-links-from-the-development-section
image

I've poked around a bit but cant see what I may have done wrong. Is this an issue with the migrator?

Reproduction Steps

  • Install ado2gh cli v1.8.0
  • Run generate-script pointing ado2gh at an ADO project where you have at least one repo, with completed and potentially in progress PRs that have links to ADO Boards work items.
  • Run the migration powershell script
  • Inspect GitHub PRs migrated, they link back to ADO work items
  • Inspect the ADO work item, it shows errors for development links to pull requests (referring to the disabled ADO repo) and they dont show any links to GitHub PRs.
@WillEllis WillEllis added the bug Something isn't working label Feb 21, 2024
@dylan-smith
Copy link
Collaborator

I was able to reproduce this. It looks like GEI is generating links in the PR description back to the AzDO work items, but the format of the link is not what the AzDO Boards <-> GitHub Integration expects. If the link format in the GH PR was AB#123 then the Boards Integration would kick in and automatically create the link on the AzDO side.

@ArinGhazarian
Copy link
Collaborator

Image

@WillEllis
Copy link
Author

WillEllis commented Feb 26, 2024

Thanks @dylan-smith and @ArinGhazarian for your input. Ive had a look but don't see where its putting those PR comments in. I assume it happens inside the GitHub CLI migration logic?

I did try to see if I could work around this limitation by querying all the PRs in GitHub and then calling ADO REST APIs to add a link to the GitHub PR, but from the ADO side its not possible to programmatically patch work items with a GitHub link due to that being controlled by the ADO GitHub app (which has a token for the connection to GitHub).

https://github.com/github/gh-gei/blob/main/src/ado2gh/Commands/ConfigureAutoLink/ConfigureAutoLinkCommandHandler.cs looks like it runs after the migration of the repo in order to configure the auto link for future PRs right? So I don't think modifying/adding to that would help unless I'm wrong.

Is this an issue that needs to be raised against the GitHub CLI itself?

@ArinGhazarian
Copy link
Collaborator

👋 @WillEllis,

Yes, this needs to be fixed in the backend since the actual repo migration happens in the GEI backend and the CLI just initiates it. I will create an issue to address this.

@WillEllis
Copy link
Author

Thanks @ArinGhazarian. In the meantime if anyone else has this issue, I have managed to work around this limitation right now by writing a script that after migration goes through all the migrated repos PRs, finds any that have "AzureDevOps/#" in the body and updates that piece of text to be "AB#". As pointed out by Dylan above, this is what the Azure Boards integration is expecting and it then does its thing and links all the PRs so they show in the ADO work items correctly.

@evervondel
Copy link

Hi @WillEllis, can you share this script?

@WillEllis
Copy link
Author

WillEllis commented Sep 20, 2024

@evervondel here you go. Its a powershell script, and you'll need to fill out the few github details at the top.

# Define GitHub repository information
$githubOrg = ""
$githubRepo = ""
$githubToken = ""
$pageSize = 100

# Function to call GitHub API to get pull requests
function Get-GitHubPullRequests {
    $url = "https://api.github.com/repos/$githubOrg/$githubRepo/pulls?state=all&per_page=$pageSize"
    $headers = @{
        "Authorization" = "token $githubToken"
    }
    $pullRequests = @()
    do {
        $response = Invoke-WebRequest -Uri $url -Headers $headers

        # Parse JSON response
        $responseData = $response.Content | ConvertFrom-Json

        # Output pull requests
        $pullRequests += $responseData

        # Check if there's another page
        $nextPageUrl = $response.RelationLink.next
        if ($nextPageUrl) {
            $url = $nextPageUrl
        } else {
            # No more pages, exit loop
            $url = $null
        }
    } while ($url)

    return $pullRequests
}

# Function to update PR description in GitHub repository
function Update-GitHubPRDescription {
    param(
        [string]$prNumber,
        [string]$updatedDescription
    )

    $url = "https://api.github.com/repos/$githubOrg/$githubRepo/pulls/$prNumber"
    $headers = @{
        "Authorization" = "token $githubToken"
        "Content-Type" = "application/json"
    }
    $body = @{
        "body" = $updatedDescription
    } | ConvertTo-Json

    Invoke-RestMethod -Uri $url -Method Patch -Headers $headers -Body $body
}

# Get all pull requests from GitHub repository
$pullRequests = Get-GitHubPullRequests

# Loop through each pull request
foreach ($pullRequest in $pullRequests) {
    $prNumber = $pullRequest.number
    $prBody = $pullRequest.body
    
    # Check if the PR body contains the string "AzureDevOps#"
    if ($prBody -like "*AzureDevOps/#*") {
        # Update the PR body by replacing "AzureDevOps#" with "AB#"
        $updatedDescription = $prBody -replace "AzureDevOps/#", "AB#"
        Write-Host "Updating description for PR $prNumber"
        
        # Call function to update the PR description
        Update-GitHubPRDescription -prNumber $prNumber -updatedDescription $updatedDescription
    }
}

@evervondel
Copy link

evervondel commented Sep 21, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants