Skip to content

Commit 6743b78

Browse files
author
Rhys Koedijk
authored
Use DevOps API version 5.0 where possible, for maximum compatibility (#1425)
* Downgrade DevOps API version from 7.1 to 5.0 * Log the full DevOps API url, including query string parameters * Fix for "isReapprove" not being set during auto-approve * Fix formatting * Update documentation * Update documentation
1 parent ebe0946 commit 6743b78

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

extension/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Dependabot uses Docker containers, which may take time to install if not already
5555
|setAutoComplete|**_Optional_**. Determines if the pull requests that dependabot creates should have auto complete set. When set to `true`, pull requests that pass all policies will be merged automatically. Defaults to `false`.|
5656
|mergeStrategy|**_Optional_**. The merge strategy to use when auto complete is set. Learn more [here](https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests/update?view=azure-devops-rest-6.0&tabs=HTTP#gitpullrequestmergestrategy). Defaults to `squash`.|
5757
|autoCompleteIgnoreConfigIds|**_Optional_**. List of any policy configuration Id's which auto-complete should not wait for. Only applies to optional policies. Auto-complete always waits for required (blocking) policies.|
58-
|autoApprove|**_Optional_**. Determines if the pull requests that dependabot creates should be automatically completed. When set to `true`, pull requests will be approved automatically. To use a different user for approval, supply `autoApproveUserToken` input. Defaults to `false`.|
58+
|autoApprove|**_Optional_**. Determines if the pull requests that dependabot creates should be automatically completed. When set to `true`, pull requests will be approved automatically. To use a different user for approval, supply `autoApproveUserToken` input. Defaults to `false`. Requires [Azure DevOps REST API 7.1](https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops#supported-versions).|
5959
|autoApproveUserToken|**_Optional_**. A personal access token for the user to automatically approve the created PR.|
6060
|authorEmail|**_Optional_**. The email address to use for the change commit author. Can be used to associate the committer with an existing account, to provide a profile picture. Defaults to `[email protected]`.|
6161
|authorName|**_Optional_**. The name to use as the git commit author of the pull requests. Defaults to `dependabot[bot]`.|
@@ -82,7 +82,7 @@ Dependabot uses Docker containers, which may take time to install if not already
8282
|setAutoComplete|**_Optional_**. Determines if the pull requests that dependabot creates should have auto complete set. When set to `true`, pull requests that pass all policies will be merged automatically. Defaults to `false`.|
8383
|mergeStrategy|**_Optional_**. The merge strategy to use when auto complete is set. Learn more [here](https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests/update?view=azure-devops-rest-6.0&tabs=HTTP#gitpullrequestmergestrategy). Defaults to `squash`.|
8484
|autoCompleteIgnoreConfigIds|**_Optional_**. List of any policy configuration Id's which auto-complete should not wait for. Only applies to optional policies. Auto-complete always waits for required (blocking) policies.|
85-
|autoApprove|**_Optional_**. Determines if the pull requests that dependabot creates should be automatically completed. When set to `true`, pull requests will be approved automatically. To use a different user for approval, supply `autoApproveUserToken` input. Defaults to `false`.|
85+
|autoApprove|**_Optional_**. Determines if the pull requests that dependabot creates should be automatically completed. When set to `true`, pull requests will be approved automatically. To use a different user for approval, supply `autoApproveUserToken` input. Defaults to `false`. Requires [Azure DevOps REST API 7.1](https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops#supported-versions).|
8686
|autoApproveUserToken|**_Optional_**. A personal access token for the user to automatically approve the created PR.|
8787
|skipPullRequests|**_Optional_**. Determines whether to skip creation and updating of pull requests. When set to `true` the logic to update the dependencies is executed but the actual Pull Requests are not created/updated. This is useful for debugging. Defaults to `false`.|
8888
|abandonUnwantedPullRequests|**_Optional_**. Determines whether to abandon unwanted pull requests. Defaults to `false`.|

extension/tasks/dependabotV1/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"label": "Auto-approve pull requests",
139139
"defaultValue": false,
140140
"required": false,
141-
"helpMarkDown": "When set to `true`, pull requests will automatically be approved by the specified user. Defaults to `false`."
141+
"helpMarkDown": "When set to `true`, pull requests will automatically be approved by the specified user. Defaults to `false`. Requires [Azure DevOps REST API 7.1](https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops#supported-versions)"
142142
},
143143
{
144144
"name": "autoApproveUserToken",

extension/tasks/dependabotV2/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"label": "Auto-approve pull requests",
119119
"defaultValue": false,
120120
"required": false,
121-
"helpMarkDown": "When set to `true`, pull requests will automatically be approved by the specified user. Defaults to `false`."
121+
"helpMarkDown": "When set to `true`, pull requests will automatically be approved by the specified user. Defaults to `false`. Requires [Azure DevOps REST API 7.1](https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops#supported-versions)"
122122
},
123123
{
124124
"name": "autoApproveUserToken",

extension/tasks/dependabotV2/utils/azure-devops/AzureDevOpsWebApiClient.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class AzureDevOpsWebApiClient {
2828
private authenticatedUserId: string;
2929
private resolvedUserIds: Record<string, string>;
3030

31-
public static API_VERSION = '7.1';
31+
public static API_VERSION = '5.0'; // this is the same version used by dependabot-core
3232

3333
constructor(organisationApiUrl: string, accessToken: string) {
3434
this.organisationApiUrl = organisationApiUrl.replace(/\/$/, ''); // trim trailing slash
@@ -464,9 +464,18 @@ export class AzureDevOpsWebApiClient {
464464
const userVote = await this.restApiPut(
465465
`${this.organisationApiUrl}/${pr.project}/_apis/git/repositories/${pr.repository}/pullrequests/${pr.pullRequestId}/reviewers/${userId}`,
466466
{
467-
vote: 10, // 10 - approved 5 - approved with suggestions 0 - no vote -5 - waiting for author -10 - rejected
468-
isReapprove: false, // don't re-approve if already approved
467+
// Vote 10 = "approved"; 5 = "approved with suggestions"; 0 = "no vote"; -5 = "waiting for author"; -10 = "rejected"
468+
vote: 10,
469+
// Reapprove must be set to true after the 2023 August 23 update;
470+
// Approval of a previous PR iteration does not count in later iterations, which means we must (re)approve every after push to the source branch
471+
// See: https://learn.microsoft.com/en-us/azure/devops/release-notes/2023/sprint-226-update#new-branch-policy-preventing-users-to-approve-their-own-changes
472+
// https://github.com/tinglesoftware/dependabot-azure-devops/issues/1069
473+
isReapprove: true,
469474
},
475+
// API version 7.1 is required to use the 'isReapprove' parameter
476+
// See: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-request-reviewers/create-pull-request-reviewer?view=azure-devops-rest-7.1&tabs=HTTP#request-body
477+
// https://learn.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops#supported-versions
478+
'7.1',
470479
);
471480
if (userVote?.vote != 10) {
472481
throw new Error('Failed to approve pull request, vote was not recorded');
@@ -619,7 +628,7 @@ export class AzureDevOpsWebApiClient {
619628
.map((key) => `${key}=${params[key]}`)
620629
.join('&');
621630
const fullUrl = `${url}?api-version=${apiVersion}${queryString ? `&${queryString}` : ''}`;
622-
return await this.restApiRequest('GET', url, () =>
631+
return await this.restApiRequest('GET', fullUrl, () =>
623632
this.connection.rest.client.get(fullUrl, {
624633
Accept: 'application/json',
625634
}),
@@ -632,7 +641,7 @@ export class AzureDevOpsWebApiClient {
632641
apiVersion: string = AzureDevOpsWebApiClient.API_VERSION,
633642
): Promise<any | undefined> {
634643
const fullUrl = `${url}?api-version=${apiVersion}`;
635-
return await this.restApiRequest('POST', url, () =>
644+
return await this.restApiRequest('POST', fullUrl, () =>
636645
this.connection.rest.client.post(fullUrl, JSON.stringify(data), {
637646
'Content-Type': 'application/json',
638647
}),
@@ -645,7 +654,7 @@ export class AzureDevOpsWebApiClient {
645654
apiVersion: string = AzureDevOpsWebApiClient.API_VERSION,
646655
): Promise<any | undefined> {
647656
const fullUrl = `${url}?api-version=${apiVersion}`;
648-
return await this.restApiRequest('PUT', url, () =>
657+
return await this.restApiRequest('PUT', fullUrl, () =>
649658
this.connection.rest.client.put(fullUrl, JSON.stringify(data), {
650659
'Content-Type': 'application/json',
651660
}),
@@ -659,7 +668,7 @@ export class AzureDevOpsWebApiClient {
659668
apiVersion: string = AzureDevOpsWebApiClient.API_VERSION,
660669
): Promise<any | undefined> {
661670
const fullUrl = `${url}?api-version=${apiVersion}`;
662-
return await this.restApiRequest('PATCH', url, () =>
671+
return await this.restApiRequest('PATCH', fullUrl, () =>
663672
this.connection.rest.client.patch(fullUrl, JSON.stringify(data), {
664673
'Content-Type': contentType || 'application/json',
665674
}),

0 commit comments

Comments
 (0)