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

fix(azure-devops): add check for test webhook URL #2809

Merged
merged 20 commits into from
Feb 22, 2023

Conversation

SSKLCP
Copy link
Contributor

@SSKLCP SSKLCP commented Dec 17, 2022

…so they aren't processed like real events

what

When setting up the webhooks in Azure DevOps you get an option to test them. Running this test fails because it points you to a repo that Atlantis has no access to and can fail ungracefully.

Adding in a check for the test webhook requests and not process them like normal requests, Returns a status 200 as the web request is working.

The check relies on the Repo URL equalling: https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079
Which is consistent across all test webhooks

why

Confusing when the webhooks are setup correctly and it shows a fail for the test.
We don't like ungraceful failures.

help

This is a first draft of what the solution could be. It feels a little bit janky to me and wasn't sure if you have a better idea of how to implement it?

The URL seemed like the most unique similarity between all the requests - Annoyingly they didn't all have a "this is a test" property.

The Commented event json is a different format to the new/updated json so I've had to put in the check twice depending on its route rather than one high level check. Again, not sure if there's a better way.

Here's all the web request bodies for the test webhooks in case you want to take a look:

Pull Request Commented On
{
  "subscriptionId": "3cff100b-52db-48fe-a774-7d51e24dd183",
  "notificationId": 267,
  "id": "af07be1b-f3ad-44c8-a7f1-c4835f2df06b",
  "eventType": "ms.vss-code.git-pullrequest-comment-event",
  "publisherId": "tfs",
  "message": {
    "text": "Jamal Hartnett has edited a pull request comment",
    "html": "Jamal Hartnett has <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5\">edited</a> a pull request comment",
    "markdown": "Jamal Hartnett has [edited](https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5) a pull request comment"
  },
  "detailedMessage": {
    "text": "Jamal Hartnett has edited a pull request comment\r\nThis is my comment.\r\n",
    "html": "Jamal Hartnett has <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5\">edited</a> a pull request comment<p>This is my comment.</p>",
    "markdown": "Jamal Hartnett has [edited](https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5) a pull request comment\r\nThis is my comment.\r\n"
  },
  "resource": {
    "comment": {
      "id": 2,
      "parentCommentId": 1,
      "author": {
        "displayName": "Jamal Hartnett",
        "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8",
        "id": "54d125f7-69f7-4191-904f-c5b96b6261c8",
        "uniqueName": "fabrikamfiber4@hotmail.com",
        "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8"
      },
      "content": "This is my comment.",
      "publishedDate": "2014-06-17T16:55:46.589889Z",
      "lastUpdatedDate": "2014-06-17T16:58:33.123889Z",
      "lastContentUpdatedDate": "2014-06-17T16:58:33.123889Z",
      "commentType": "text",
      "_links": {
        "self": {
          "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/threads/5/comments/2"
        },
        "repository": {
          "href": "http://joscol2/DefaultCollection/ebed510c-62eb-474b-965f-fd151ebb82e4/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079"
        },
        "threads": {
          "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/threads/5"
        }
      }
    },
    "pullRequest": {
      "repository": {
        "id": "4bc14d40-c903-45e2-872e-0462c7748079",
        "name": "Fabrikam",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079",
        "project": {
          "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
          "name": "Fabrikam",
          "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
          "state": "wellFormed",
          "visibility": "unchanged",
          "lastUpdateTime": "0001-01-01T00:00:00"
        },
        "defaultBranch": "refs/heads/master",
        "remoteUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam"
      },
      "pullRequestId": 1,
      "status": "active",
      "createdBy": {
        "displayName": "Jamal Hartnett",
        "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8",
        "id": "54d125f7-69f7-4191-904f-c5b96b6261c8",
        "uniqueName": "fabrikamfiber4@hotmail.com",
        "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8"
      },
      "creationDate": "2014-06-17T16:55:46.589889Z",
      "title": "my first pull request",
      "description": " - test2\r\n",
      "sourceRefName": "refs/heads/mytopic",
      "targetRefName": "refs/heads/master",
      "mergeStatus": "succeeded",
      "mergeId": "a10bb228-6ba6-4362-abd7-49ea21333dbd",
      "lastMergeSourceCommit": {
        "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c"
      },
      "lastMergeTargetCommit": {
        "commitId": "a511f535b1ea495ee0c903badb68fbc83772c882",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/a511f535b1ea495ee0c903badb68fbc83772c882"
      },
      "lastMergeCommit": {
        "commitId": "eef717f69257a6333f221566c1c987dc94cc0d72",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72"
      },
      "reviewers": [
        {
          "reviewerUrl": null,
          "vote": 0,
          "displayName": "[Mobile]\\Mobile Team",
          "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/2ea2d095-48f9-4cd6-9966-62f6f574096c",
          "id": "2ea2d095-48f9-4cd6-9966-62f6f574096c",
          "uniqueName": "vstfs:///Classification/TeamProject/f0811a3b-8c8a-4e43-a3bf-9a049b4835bd\\Mobile Team",
          "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=2ea2d095-48f9-4cd6-9966-62f6f574096c",
          "isContainer": true
        }
      ],
      "commits": [
        {
          "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c",
          "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c"
        }
      ],
      "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1",
      "_links": {
        "web": {
          "href": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1#view=discussion"
        },
        "statuses": {
          "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/statuses"
        }
      }
    }
  },
  "resourceVersion": "2.0",
  "resourceContainers": {
    "collection": {
      "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2"
    },
    "account": {
      "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e"
    },
    "project": {
      "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f"
    }
  },
  "createdDate": "2022-12-17T08:18:08.0981478Z"
}
Pull Request Created
{
  "subscriptionId": "bed09de0-2579-4ff1-8b19-5582f8d03eba",
  "notificationId": 8,
  "id": "2ab4e3d3-b7a6-425e-92b1-5a9982c1269e",
  "eventType": "git.pullrequest.created",
  "publisherId": "tfs",
  "message": {
    "text": "Jamal Hartnett created a new pull request",
    "html": "Jamal Hartnett created a new pull request",
    "markdown": "Jamal Hartnett created a new pull request"
  },
  "detailedMessage": {
    "text": "Jamal Hartnett created a new pull request\r\n\r\n- Merge status: Succeeded\r\n- Merge commit: eef717(https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72)\r\n",
    "html": "Jamal Hartnett created a new pull request\r\n<ul>\r\n<li>Merge status: Succeeded</li>\r\n<li>Merge commit: <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72\">eef717</a></li>\r\n</ul>",
    "markdown": "Jamal Hartnett created a new pull request\r\n\r\n+ Merge status: Succeeded\r\n+ Merge commit: [eef717](https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72)\r\n"
  },
  "resource": {
    "repository": {
      "id": "4bc14d40-c903-45e2-872e-0462c7748079",
      "name": "Fabrikam",
      "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079",
      "project": {
        "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
        "name": "Fabrikam",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
        "state": "wellFormed",
        "visibility": "unchanged",
        "lastUpdateTime": "0001-01-01T00:00:00"
      },
      "defaultBranch": "refs/heads/master",
      "remoteUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam"
    },
    "pullRequestId": 1,
    "status": "active",
    "createdBy": {
      "displayName": "Jamal Hartnett",
      "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8",
      "id": "54d125f7-69f7-4191-904f-c5b96b6261c8",
      "uniqueName": "fabrikamfiber4@hotmail.com",
      "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8"
    },
    "creationDate": "2014-06-17T16:55:46.589889Z",
    "title": "my first pull request",
    "description": " - test2\r\n",
    "sourceRefName": "refs/heads/mytopic",
    "targetRefName": "refs/heads/master",
    "mergeStatus": "succeeded",
    "mergeId": "a10bb228-6ba6-4362-abd7-49ea21333dbd",
    "lastMergeSourceCommit": {
      "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c",
      "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c"
    },
    "lastMergeTargetCommit": {
      "commitId": "a511f535b1ea495ee0c903badb68fbc83772c882",
      "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/a511f535b1ea495ee0c903badb68fbc83772c882"
    },
    "lastMergeCommit": {
      "commitId": "eef717f69257a6333f221566c1c987dc94cc0d72",
      "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72"
    },
    "reviewers": [
      {
        "reviewerUrl": null,
        "vote": 0,
        "displayName": "[Mobile]\\Mobile Team",
        "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/2ea2d095-48f9-4cd6-9966-62f6f574096c",
        "id": "2ea2d095-48f9-4cd6-9966-62f6f574096c",
        "uniqueName": "vstfs:///Classification/TeamProject/f0811a3b-8c8a-4e43-a3bf-9a049b4835bd\\Mobile Team",
        "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=2ea2d095-48f9-4cd6-9966-62f6f574096c",
        "isContainer": true
      }
    ],
    "commits": [
      {
        "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c"
      }
    ],
    "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1",
    "_links": {
      "web": {
        "href": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1#view=discussion"
      },
      "statuses": {
        "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/statuses"
      }
    }
  },
  "resourceVersion": "1.0",
  "resourceContainers": {
    "collection": {
      "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2"
    },
    "account": {
      "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e"
    },
    "project": {
      "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f"
    }
  },
  "createdDate": "2022-12-17T08:19:48.5718178Z"
}
Pull Request Updated
{
    "subscriptionId": "7811574c-a1cd-401d-9370-5de70f3c8fe9",
    "notificationId": 60,
    "id": "af07be1b-f3ad-44c8-a7f1-c4835f2df06b",
    "eventType": "git.pullrequest.updated",
    "publisherId": "tfs",
    "message": {
      "text": "Jamal Hartnett marked the pull request as completed",
      "html": "Jamal Hartnett marked the pull request as completed",
      "markdown": "Jamal Hartnett marked the pull request as completed"
    },
    "detailedMessage": {
      "text": "Jamal Hartnett marked the pull request as completed\r\n\r\n- Merge status: Succeeded\r\n- Merge commit: eef717(https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72)\r\n",
      "html": "Jamal Hartnett marked the pull request as completed\r\n<ul>\r\n<li>Merge status: Succeeded</li>\r\n<li>Merge commit: <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72\">eef717</a></li>\r\n</ul>",
      "markdown": "Jamal Hartnett marked the pull request as completed\r\n\r\n+ Merge status: Succeeded\r\n+ Merge commit: [eef717](https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72)\r\n"
    },
    "resource": {
      "repository": {
        "id": "4bc14d40-c903-45e2-872e-0462c7748079",
        "name": "Fabrikam",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079",
        "project": {
          "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
          "name": "Fabrikam",
          "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
          "state": "wellFormed",
          "visibility": "unchanged",
          "lastUpdateTime": "0001-01-01T00:00:00"
        },
        "defaultBranch": "refs/heads/master",
        "remoteUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam"
      },
      "pullRequestId": 1,
      "status": "completed",
      "createdBy": {
        "displayName": "Jamal Hartnett",
        "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8",
        "id": "54d125f7-69f7-4191-904f-c5b96b6261c8",
        "uniqueName": "fabrikamfiber4@hotmail.com",
        "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8"
      },
      "creationDate": "2014-06-17T16:55:46.589889Z",
      "closedDate": "2014-06-30T18:59:12.3660573Z",
      "title": "my first pull request",
      "description": " - test2\r\n",
      "sourceRefName": "refs/heads/mytopic",
      "targetRefName": "refs/heads/master",
      "mergeStatus": "succeeded",
      "mergeId": "a10bb228-6ba6-4362-abd7-49ea21333dbd",
      "lastMergeSourceCommit": {
        "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c"
      },
      "lastMergeTargetCommit": {
        "commitId": "a511f535b1ea495ee0c903badb68fbc83772c882",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/a511f535b1ea495ee0c903badb68fbc83772c882"
      },
      "lastMergeCommit": {
        "commitId": "eef717f69257a6333f221566c1c987dc94cc0d72",
        "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72"
      },
      "reviewers": [
        {
          "reviewerUrl": null,
          "vote": 0,
          "displayName": "[Mobile]\\Mobile Team",
          "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/2ea2d095-48f9-4cd6-9966-62f6f574096c",
          "id": "2ea2d095-48f9-4cd6-9966-62f6f574096c",
          "uniqueName": "vstfs:///Classification/TeamProject/f0811a3b-8c8a-4e43-a3bf-9a049b4835bd\\Mobile Team",
          "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=2ea2d095-48f9-4cd6-9966-62f6f574096c",
          "isContainer": true
        }
      ],
      "commits": [
        {
          "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c",
          "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c"
        }
      ],
      "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1",
      "_links": {
        "web": {
          "href": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1#view=discussion"
        },
        "statuses": {
          "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/statuses"
        }
      }
    },
    "resourceVersion": "1.0",
    "resourceContainers": {
      "collection": {
        "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2"
      },
      "account": {
        "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e"
      },
      "project": {
        "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f"
      }
    },
    "createdDate": "2022-12-17T08:20:49.4937995Z"
  }
  

references

@SSKLCP SSKLCP requested a review from a team as a code owner December 17, 2022 15:21
@nitrocode nitrocode changed the title Adding check for Azure DevOps Test Webhook URL ... bugfix: Adding check for Azure DevOps Test Webhook URL Dec 19, 2022
@nitrocode nitrocode marked this pull request as draft December 22, 2022 14:05
@nitrocode nitrocode marked this pull request as ready for review December 22, 2022 16:47
@nitrocode nitrocode added the needs tests Change requires tests label Dec 22, 2022
@nitrocode nitrocode added this to the 0.22.0 milestone Dec 23, 2022
@nitrocode nitrocode added the waiting-on-response Waiting for a response from the user label Dec 27, 2022
@nitrocode
Copy link
Member

@SSKLCP this is the last issue we have for our next release milestone 0.22.0. Is this something that you can work on in the next week or so?

If not, we'll have to include it in a follow up release.

@nitrocode nitrocode modified the milestones: 0.22.0, 0.22.1 Jan 2, 2023
@SSKLCP
Copy link
Contributor Author

SSKLCP commented Jan 5, 2023

Sorry @nitrocode - Not had time over the holidays.
Push it back into the next release and I'll pick it up next week.

@nitrocode nitrocode modified the milestones: 0.22.2, 0.22.3 Jan 6, 2023
@nitrocode nitrocode modified the milestones: 0.22.3, 0.23.0 Jan 10, 2023
Copy link
Contributor

@krrrr38 krrrr38 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

server/controllers/events/events_controller.go Outdated Show resolved Hide resolved
@@ -43,6 +43,9 @@ const bitbucketCloudRequestIDHeader = "X-Request-UUID"
const bitbucketServerRequestIDHeader = "X-Request-ID"
const bitbucketServerSignatureHeader = "X-Hub-Signature"

// The URL used for Azure DevOps test webhooks
const azuredevopsTestURL = "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this url has to be hardcoded?

Shouldn't this value be in the test instead?

Who has access to use this url for testing purposes?

Couldn't this be mocked?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is to detect and ignore the test webhooks that come from Azure DevOps. The test requests for the 3 webhooks that Atlantis uses are in the PR description. (The tests aren't configurable, they just send the same requests every time)

The URL is a common property that exists in all three requests so we're using it to say: "If the request says it's coming from this URL: Ignore the request"

No access is needed to this URL, we're simply using it to identify these test requests.

Does that sound okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we'll ever have to configure these urls?

Would you add some additional comments in the code to add this explaination in case people have this question in the future?

@nitrocode nitrocode changed the title bugfix: Adding check for Azure DevOps Test Webhook URL fix(azure-devops): add check for test webhook URL Jan 16, 2023
@@ -43,6 +43,9 @@ const bitbucketCloudRequestIDHeader = "X-Request-UUID"
const bitbucketServerRequestIDHeader = "X-Request-ID"
const bitbucketServerSignatureHeader = "X-Hub-Signature"

// The URL used for Azure DevOps test webhooks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this PR been tested in your atlantis deployment? Were you able to verify that this change worked as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll build it and run through some tests - hold off until I've confirmed that's sorted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Once you confirm then we can merge

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SSKLCP friendly ping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SSKLCP friendly ping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SSKLCP friendly ping

Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>
@nitrocode nitrocode removed the needs tests Change requires tests label Jan 30, 2023
@github-actions github-actions bot added the go Pull requests that update Go code label Feb 19, 2023
Copy link
Member

@chenrui333 chenrui333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nitrocode nitrocode merged commit 50de813 into runatlantis:main Feb 22, 2023
@nitrocode
Copy link
Member

Thank you @SSKLCP !

@nitrocode nitrocode removed the waiting-on-response Waiting for a response from the user label Feb 22, 2023
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* Adding check for Azure DevOps Test Webhook URL so they aren't processed like real events

* feat: customize vcs comment command executable name

* Altering case on isAzureDevOpsTestRepoURL function

* Altering case on URL parameter

* Altering checks to ensure all Azure DevOps Ignore tests pass

* Extending setup method to support Azure DevOps

* Fixing issue from merge conflict error

* gofmt

* Adding null checks to Test URL checks

* moving azuredevopsTestUrl to const

* Changing azuredevopsTestUrl to azuredevopsTestURL

* Cleaning up return statement

Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>

---------

Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* Adding check for Azure DevOps Test Webhook URL so they aren't processed like real events

* feat: customize vcs comment command executable name

* Altering case on isAzureDevOpsTestRepoURL function

* Altering case on URL parameter

* Altering checks to ensure all Azure DevOps Ignore tests pass

* Extending setup method to support Azure DevOps

* Fixing issue from merge conflict error

* gofmt

* Adding null checks to Test URL checks

* moving azuredevopsTestUrl to const

* Changing azuredevopsTestUrl to azuredevopsTestURL

* Cleaning up return statement

Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>

---------

Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Azure DevOps webhook 401 unauthorized error Azure devops webhooks don't work
4 participants