Skip to content

Commit 710fb06

Browse files
feat: enable compatible change for legacy and new ADO url (#5596)
Signed-off-by: Leonardo Quatrocchi <[email protected]>
1 parent 5dfe5f9 commit 710fb06

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

runatlantis.io/docs/server-configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ and set `--autoplan-modules` to `false`.
241241

242242
Azure DevOps hostname to support cloud and self hosted instances. Defaults to `dev.azure.com`.
243243

244+
::: warning COMPATIBILITY WARNING
245+
If you are affected by this change [docs](https://learn.microsoft.com/en-us/azure/devops/release-notes/2018/sep-10-azure-devops-launch#administration)
246+
or this [issue](https://github.com/runatlantis/atlantis/issues/5595)
247+
both Service Hooks (v1 & v2) will convert the AD Organization name to lowercase:
248+
Examples:
249+
`https://dev.azure.com/MYCompany/` & `https://mycompany.visualstudio.com/` will be converted to `mycompany`
250+
`https://dev.azure.com/MYCOMPANY/` & `https://myCOMPANY.visualstudio.com/` will be converted to `mycompany`
251+
252+
This [change](https://github.com/runatlantis/atlantis/pull/5596) will be applied from version v0.35.0
253+
254+
What to do if you have pending plans that were generated with a previous version?
255+
Running an atlantis unlock from v0.35.0 on your current PRs will ignore the files on the `MYCompany` folder. On the next atlantis plan will use the `mycompany` folder and generate everything in the new folder name
256+
:::
257+
244258
### `--azuredevops-token`
245259

246260
```bash

server/events/event_parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,12 @@ func (e *EventParser) ParseAzureDevopsRepo(adRepo *azuredevops.GitRepository) (m
10291029
} else {
10301030
owner = strings.Split(uri.Path, "/")[1]
10311031
}
1032+
owner = strings.ToLower(owner)
1033+
// Important Issue
1034+
// Details in here: https://github.com/runatlantis/atlantis/issues/5595
1035+
// Original issue from 2018: https://github.com/runatlantis/atlantis/issues/1858
1036+
// Related Microsoft article: https://learn.microsoft.com/en-us/azure/devops/release-notes/2018/sep-10-azure-devops-launch#administration
1037+
// If Azure DevOps forces the usage of new url, we need to remove all the changes added on this pull request (1 line and 1 test)
10321038
}
10331039

10341040
// Construct our own clone URL so we always get the new dev.azure.com

server/events/event_parser_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,36 @@ func TestParseAzureDevopsRepo(t *testing.T) {
13311331
}, r)
13321332
}
13331333

1334+
func TestParseAzureDevopsRepo_LowercasesOwner(t *testing.T) {
1335+
parser := events.EventParser{
1336+
AzureDevopsUser: "azuredevops-user",
1337+
AzureDevopsToken: "azuredevops-token",
1338+
}
1339+
1340+
tests := []struct {
1341+
url string
1342+
expected string
1343+
}{
1344+
{"https://dev.azure.com/MyCompany/project/_git/repo", "mycompany"},
1345+
{"https://MYCOMPANY.visualstudio.com/project/_git/repo", "mycompany"},
1346+
{"https://AnotherOrg.visualstudio.com/project/_git/repo", "anotherorg"},
1347+
}
1348+
1349+
for _, tt := range tests {
1350+
repo := azuredevops.GitRepository{}
1351+
repo.WebURL = azuredevops.String(tt.url)
1352+
repo.ParentRepository = nil
1353+
repo.Project = &azuredevops.TeamProjectReference{Name: azuredevops.String("project")}
1354+
repo.Name = azuredevops.String("repo")
1355+
1356+
r, err := parser.ParseAzureDevopsRepo(&repo)
1357+
Ok(t, err)
1358+
// Only check the owner part
1359+
parts := strings.Split(r.FullName, "/")
1360+
owner := parts[0]
1361+
Equals(t, tt.expected, owner)
1362+
}
1363+
}
13341364
func TestParseAzureDevopsPullEvent(t *testing.T) {
13351365
_, _, _, _, _, err := parser.ParseAzureDevopsPullEvent(ADPullEvent)
13361366
Ok(t, err)

0 commit comments

Comments
 (0)