Skip to content

Commit 10bc9a3

Browse files
authored
fix(hook): fix branch and hash on pullrequest event + add docs (#5105)
1 parent 88936dc commit 10bc9a3

File tree

4 files changed

+145
-113
lines changed

4 files changed

+145
-113
lines changed

docs/content/docs/concepts/variables.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,46 @@ echo $CDS_PARENT_APPLICATION
9797

9898
Here is the list of git variables:
9999

100-
- `{{.git.hash}}`
101-
- `{{.git.hash.short}}`
102-
- `{{.git.url}}`
103-
- `{{.git.http_url}}`
104-
- `{{.git.branch}}`
105-
- `{{.git.tag}}`
106-
- `{{.git.author}}`
107-
- `{{.git.message}}`
108-
- `{{.git.server}}`
100+
- `{{.git.hash.before}}`: SHA of the most recent commit before the push
101+
- `{{.git.hash}}`: SHA of the most recent commit after the push
102+
- `{{.git.hash.short}}`: Short version of git.hash
103+
- `{{.git.hook}}`: Name of the event that trigger the run
104+
- `{{.git.url}}`: Git ssh URL used to clone
105+
- `{{.git.http_url}}`: Git http url used to clone
106+
- `{{.git.branch}}`:
107+
- Push event: Name of the branch where the push occured
108+
- PullRequest event: Name of the source branch
109+
- `{{.git.tag}}`: Name of the tag that triggered the run
110+
- `{{.git.author}}`: Name of the most recent commit author
111+
- `{{.git.author.email}}`: Email of the most recent commit author
112+
- `{{.git.message}}`: Git message of the most recent commit
113+
- `{{.git.server}}`: Name of the repository manager
114+
- `{{.git.repository}}`:
115+
- Push event: Name of the repository
116+
- PullRequest event: Name of the source repository
117+
118+
Here is the list of git variables available only for Bitbucket server
119+
120+
- `{{.git.hash.dest}}`: SHA of the most rcent commit on destination branch ( PullRequest event )
121+
- `{{.git.branch.dest}}`: Name of the destination branch on a pull request event
122+
- `{{.git.repository.dest}}`: Name of the target repository on a pull request event
123+
- `{{.git.pr.id}}`: Identifier of the pullrequest
124+
- `{{.git.pr.title}}`: Title of the pullrequest
125+
- `{{.git.pr.state}}`: Status of the pullrequest
126+
- `{{.git.pr.previous.title}}`: Previous title of the pullrequest
127+
- `{{.git.pr.previous.branch}}`: Previous target branch of the pullrequest
128+
- `{{.git.pr.previous.hash}}`: Previous target hash of the pullrequest
129+
- `{{.git.pr.previous.state}}`: Previous status of the pullrequest
130+
- `{{.git.pr.reviewer}}`: Name of the reviewer
131+
- `{{.git.pr.reviewer.email}}`: Email of the reviewer
132+
- `{{.git.pr.reviewer.status}}`: Status of the review
133+
- `{{.git.pr.reviewer.role}}`: Role of the reviewer
134+
- `{{.git.pr.comment}}`: Comment written by the reviewer
135+
- `{{.git.pr.comment.before}}`: Previous comment
136+
- `{{.git.pr.comment.author}}`: Author name of the comment
137+
- `{{.git.pr.comment.author.email}}` Author email of the comment
138+
139+
109140

110141
## Pipeline parameters
111142

engine/hooks/bitbucket_server.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ func getVariableFromBitbucketServerRepository(payload map[string]interface{}, re
9191
if repo == nil {
9292
return
9393
}
94-
payload[GIT_REPOSITORY] = fmt.Sprintf("%s/%s", repo.Project.Key, repo.Slug)
94+
payload[GIT_REPOSITORY_DEST] = fmt.Sprintf("%s/%s", repo.Project.Key, repo.Slug)
9595
}
9696

9797
func getVariableFromBitbucketServerSrcRepository(payload map[string]interface{}, repo *sdk.BitbucketServerRepository) {
9898
if repo == nil {
9999
return
100100
}
101-
payload[GIT_REPOSITORY_BEFORE] = fmt.Sprintf("%s/%s", repo.Project.Key, repo.Slug)
101+
payload[GIT_REPOSITORY] = fmt.Sprintf("%s/%s", repo.Project.Key, repo.Slug)
102102
}
103103

104104
func getVariableFromBitbucketServerAuthor(payload map[string]interface{}, actor *sdk.BitbucketServerActor) {
@@ -119,11 +119,11 @@ func getVariableFromBitbucketServerPullRequest(payload map[string]interface{}, p
119119
payload[PR_ID] = pr.ID
120120
payload[PR_STATE] = pr.State
121121
payload[PR_TITLE] = pr.Title
122-
payload[GIT_BRANCH_BEFORE] = pr.FromRef.DisplayID
123-
payload[GIT_HASH_BEFORE] = pr.FromRef.LatestCommit
124-
payload[GIT_BRANCH] = pr.ToRef.DisplayID
125-
payload[GIT_HASH] = pr.ToRef.LatestCommit
126-
hashShort := pr.ToRef.LatestCommit
122+
payload[GIT_BRANCH] = pr.FromRef.DisplayID
123+
payload[GIT_HASH] = pr.FromRef.LatestCommit
124+
payload[GIT_BRANCH_DEST] = pr.ToRef.DisplayID
125+
payload[GIT_HASH_DEST] = pr.ToRef.LatestCommit
126+
hashShort := pr.FromRef.LatestCommit
127127
if len(hashShort) >= 7 {
128128
hashShort = hashShort[:7]
129129
}

0 commit comments

Comments
 (0)