I have a github service connection that has permissions for my enterprise git server. My script however other than cloning repos does some analysis on github more gitrepos by using the github API.
I wanted to use the service connection to authenticate to the API instead of defining a new token(which works) so I can use this to get repos from the API for example I am fetching all repos beginning with a give prefix and reporting back some statistics
You can install the third-party extension Github AzureDevOps Rest Api Integration in your organization and then use the GitHub service connection for authentication.
For example, call GitHub API to create a PR:
- task: azuredevopsgithub@0
inputs:
gitHubConnection: '{The GitHub service connection you created}'
method: 'POST'
body: |
{
"title": "Merging changes from branch1 to main",
"head": "refs/heads/branch1",
"base": "refs/heads/main",
"body": "Test creating PR in Azure pipeline"
}
githubrestapiurl: 'https://api.github.com/repos/{GitHubOwner}/{Repo}/pulls'