Repository: runatlantis/atlantis (language: go)

Issue:
`if` with identical `then` and `else` branches
In the following code, both control branches do the same (i.e. `owner = strings.Split(uri.Path, "/")[1]`)

https://github.com/runatlantis/atlantis/blob/2cd8bd9ccca1f496347b1b9b0d9a75308e151650/server/events/event_parser.go#L926-L930

Found by [revive](https://github.com/mgechev/revive) (rule [`identical-branches`](https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#identical-branches))
`if` with identical `then` and `else` branches
In the following code, both control branches do the same (i.e. `owner = strings.Split(uri.Path, "/")[1]`)

https://github.com/runatlantis/atlantis/blob/2cd8bd9ccca1f496347b1b9b0d9a75308e151650/server/events/event_parser.go#L926-L930

Found by [revive](https://github.com/mgechev/revive) (rule [`identical-branches`](https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#identical-branches))


Discussion / hints:
yes but one will match a hostname and the other will not.

how do you propose to make it better?
>yes but one will match a hostname and the other will not.

As is written, the value of `owner` does not depend on the condition (`strings.Contains(uri.Host, "dev.azure.com")`)

> how do you propose to make it better?

In general, if both branches do the same, the full if-statement can be safely replaced with any of its branches, therefore
```go
		if strings.Contains(uri.Host, "visualstudio.com") {
			owner = strings.Split(uri.Host, ".")[0]
		} else if strings.Contains(uri.Host, "dev.azure.com") {
			owner = strings.Split(uri.Path, "/")[1]
		} else {
			owner = strings.Split(uri.Path, "/")[1] // to support owner for self hosted
		}
```
can be rewritten as
```go
		if strings.Contains(uri.Host, "visualstudio.com") {
			owner = strings.Split(uri.Host, ".")[0]
		} else {
			owner = strings.Split(uri.Path, "/")[1]
		} 
```

Warn: accessing the second element of the result of a `strings.Split` (as in `strings.Split(uri.Path, "/")[1]`) can lead to a runtime error if the result of the split is a slice shorter than 2
I C  what you mean, yes , that could be improved, are you willing to send a PR over?
Yes, sure, you can assign the issue to me
I can't assign to you, it does not let me because you are not in the maintainers list
yes but one will match a hostname and the other will not.

how do you propose to make it better?
>yes but one will match a hostname and the other will not.

As is written, the value of `owner` does not depend on the condition (`strings.Contains(uri.Host, "dev.azure.com")`)

> how do you propose to make it better?

In general, if both branches do the same, the full if-statement can be safely replaced with any of its branches, therefore
```go
		if strings.Contains(uri.Host, "visualstudio.com") {
			owner = strings.Split(uri.Host, ".")[0]
		} else if strings.Contains(uri.Host, "dev.azure.com") {
			owner = strings.Split(uri.Path, "/")[1]
		} else {
			owner = strings.Split(uri.Path, "/")[1] // to support owner for self hosted
		}
```
can be rewritten as
```go
		if strings.Contains(uri.Host, "visualstudio.com") {
			owner = strings.Split(uri.Host, ".")[0]
		} else {
			owner = strings.Split(uri.Path, "/")[1]
		} 
```

Warn: accessing the second element of the result of a `strings.Split` (as in `strings.Split(uri.Path, "/")[1]`) can lead to a runtime error if the result of the split is a slice shorter than 2
I C  what you mean, yes , that could be improved, are you willing to send a PR over?
Yes, sure, you can assign the issue to me
I can't assign to you, it does not let me because you are not in the maintainers list

Fix patch:
diff --git a/server/events/event_parser.go b/server/events/event_parser.go
index 194e5344c8..3d8dc6550a 100644
--- a/server/events/event_parser.go
+++ b/server/events/event_parser.go
@@ -923,10 +923,8 @@ func (e *EventParser) ParseAzureDevopsRepo(adRepo *azuredevops.GitRepository) (m
 
 		if strings.Contains(uri.Host, "visualstudio.com") {
 			owner = strings.Split(uri.Host, ".")[0]
-		} else if strings.Contains(uri.Host, "dev.azure.com") {
-			owner = strings.Split(uri.Path, "/")[1]
 		} else {
-			owner = strings.Split(uri.Path, "/")[1] // to support owner for self hosted
+			owner = strings.Split(uri.Path, "/")[1]
 		}
 	}
 


Test patch: