Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
    - Improve tests
    - Replace instead of Split
  • Loading branch information
mcdafydd committed Nov 14, 2019
1 parent 71239cf commit 09eb6ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions server/events/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,14 +788,15 @@ func (e *EventParser) ParseAzureDevopsPull(pull *azuredevops.GitPullRequest) (pu
}

pullModel = models.PullRequest{
Author: authorUsername,
HeadBranch: strings.SplitAfterN(headBranch, "/", 3)[2],
Author: authorUsername,
// Change webhook refs from "refs/heads/<branch>" to "<branch>"
HeadBranch: strings.Replace(headBranch, "refs/heads/", "", 1),
HeadCommit: commit,
URL: url,
Num: num,
State: pullState,
BaseRepo: baseRepo,
BaseBranch: strings.SplitAfterN(baseBranch, "/", 3)[2],
BaseBranch: strings.Replace(baseBranch, "refs/heads/", "", 1),
}
return
}
Expand Down
8 changes: 4 additions & 4 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,8 @@ func TestParseAzureDevopsPullEvent(t *testing.T) {
Equals(t, models.PullRequest{
URL: ADPull.GetURL(),
Author: ADPull.CreatedBy.GetUniqueName(),
HeadBranch: strings.SplitAfterN(ADPull.GetSourceRefName(), "/", 3)[2],
BaseBranch: strings.SplitAfterN(ADPull.GetTargetRefName(), "/", 3)[2],
HeadBranch: "feature/sourceBranch",
BaseBranch: "targetBranch",
HeadCommit: ADPull.LastMergeSourceCommit.GetCommitID(),
Num: ADPull.GetPullRequestID(),
State: models.OpenPullState,
Expand Down Expand Up @@ -1257,8 +1257,8 @@ func TestParseAzureDevopsPull(t *testing.T) {
Equals(t, models.PullRequest{
URL: ADPull.GetURL(),
Author: ADPull.CreatedBy.GetUniqueName(),
HeadBranch: strings.SplitAfterN(ADPull.GetSourceRefName(), "/", 3)[2],
BaseBranch: strings.SplitAfterN(ADPull.GetTargetRefName(), "/", 3)[2],
HeadBranch: "feature/sourceBranch",
BaseBranch: "targetBranch",
HeadCommit: ADPull.LastMergeSourceCommit.GetCommitID(),
Num: ADPull.GetPullRequestID(),
State: models.OpenPullState,
Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var ADPull = azuredevops.GitPullRequest{
},
PullRequestID: azuredevops.Int(1),
Repository: &ADRepo,
SourceRefName: azuredevops.String("refs/heads/owner/feature/sourceBranch"),
SourceRefName: azuredevops.String("refs/heads/feature/sourceBranch"),
Status: azuredevops.String("active"),
TargetRefName: azuredevops.String("refs/heads/targetBranch"),
URL: azuredevops.String("https://dev.azure.com/fabrikam/_apis/git/repositories/3411ebc1-d5aa-464f-9615-0b527bc66719/pullRequests/21"),
Expand Down

0 comments on commit 09eb6ac

Please sign in to comment.