Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions service/hook/visualstudioteamservices/visualstudioteamservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func transformPushEvent(pushEvent PushEventModel) hookCommon.TransformResultMode
branch := strings.TrimPrefix(pushRef, "refs/heads/")

if len(pushEvent.Resource.Commits) < 1 {
var commitMessage string
commitHash := headRefUpdate.NewObjectID
if commitHash == emptyCommitHash {
// no commits and the (new) commit hash is empty -> this is a delete event,
Expand All @@ -147,15 +148,17 @@ func transformPushEvent(pushEvent PushEventModel) hookCommon.TransformResultMode
}
}
if headRefUpdate.OldObjectID == emptyCommitHash {
commitMessage = "Branch created"
// (new) commit hash was not empty, but old one is -> this is a create event,
// without any commits pushed, just the branch created
return hookCommon.TransformResultModel{
TriggerAPIParams: []bitriseapi.TriggerAPIParamsModel{
{
BuildParams: bitriseapi.BuildParamsModel{
Branch: branch,
CommitHash: commitHash,
CommitMessage: "Branch created",
Branch: branch,
CommitHash: commitHash,
CommitMessage: commitMessage,
CommitMessages: []string{commitMessage},
},
},
},
Expand All @@ -170,13 +173,15 @@ func transformPushEvent(pushEvent PushEventModel) hookCommon.TransformResultMode
// `git log`, but it does not include it in the hook event,
// only the head ref change.
// So, for now, we'll use the event's detailed message as the commit message.
commitMessage = pushEvent.DetailedMessage.Text
return hookCommon.TransformResultModel{
TriggerAPIParams: []bitriseapi.TriggerAPIParamsModel{
{
BuildParams: bitriseapi.BuildParamsModel{
Branch: branch,
CommitHash: commitHash,
CommitMessage: pushEvent.DetailedMessage.Text,
Branch: branch,
CommitHash: commitHash,
CommitMessage: commitMessage,
CommitMessages: []string{commitMessage},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,10 @@ func Test_transformPushEvent(t *testing.T) {
require.Equal(t, []bitriseapi.TriggerAPIParamsModel{
{
BuildParams: bitriseapi.BuildParamsModel{
Branch: "test-branch",
CommitHash: "7c0d90dc542b86747e42ac8f03f794a96ecfc68a",
CommitMessage: "Branch created",
Branch: "test-branch",
CommitHash: "7c0d90dc542b86747e42ac8f03f794a96ecfc68a",
CommitMessage: "Branch created",
CommitMessages: []string{"Branch created"},
},
},
}, hookTransformResult.TriggerAPIParams)
Expand Down Expand Up @@ -469,9 +470,10 @@ func Test_transformPushEvent(t *testing.T) {
require.Equal(t, []bitriseapi.TriggerAPIParamsModel{
{
BuildParams: bitriseapi.BuildParamsModel{
Branch: "master",
CommitHash: "7c0d90dc542b86747e42ac8f03f794a96ecfc68a",
CommitMessage: "Author Name pushed 4 commits to branch master of test project\r\n - PR 3: Merge feature/new-branch-test to master 293d9ead ...",
Branch: "master",
CommitHash: "7c0d90dc542b86747e42ac8f03f794a96ecfc68a",
CommitMessage: "Author Name pushed 4 commits to branch master of test project\r\n - PR 3: Merge feature/new-branch-test to master 293d9ead ...",
CommitMessages: []string{"Author Name pushed 4 commits to branch master of test project\r\n - PR 3: Merge feature/new-branch-test to master 293d9ead ..."},
},
},
}, hookTransformResult.TriggerAPIParams)
Expand Down