From 7464d43ff7aef99ef4c30d8bdea4dcc66dca7844 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Sun, 21 Jul 2019 22:09:46 -0700 Subject: [PATCH] fix access_token_type for PR's --- pkg/scm/scm_github.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/scm/scm_github.go b/pkg/scm/scm_github.go index ddda09f..3c8cf29 100644 --- a/pkg/scm/scm_github.go +++ b/pkg/scm/scm_github.go @@ -203,7 +203,19 @@ func (g *scmGithub) CheckoutPullRequestPayload(payload *Payload) error { return berr } - authRemote, aerr := authGitRemote(g.PipelineData.GitBaseInfo.Repo.CloneUrl, g.Config.GetString("scm_github_access_token"), "") + var gitRemoteUsername string + var gitRemotePassword string + + if g.Config.GetString("scm_github_access_token_type") == "app" { + // see https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/ + gitRemoteUsername = "x-access-token" + gitRemotePassword = g.Config.GetString("scm_github_access_token") + } else { + gitRemoteUsername = g.Config.GetString("scm_github_access_token") + gitRemotePassword = "" + } + + authRemote, aerr := authGitRemote(g.PipelineData.GitBaseInfo.Repo.CloneUrl, gitRemoteUsername, gitRemotePassword) if aerr != nil { return aerr }