Skip to content

Commit

Permalink
fix: 🐛 github permissions error (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskaransarkaria authored Sep 25, 2024
1 parent 3f6322b commit 01e1450
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/environment/createPR.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ministryofjustice/cloud-platform-cli/pkg/slack"
)

func createPR(description, namespace string) func(github.GithubIface, []string) (string, error) {
func createPR(description, namespace, ghToken, repo string) func(github.GithubIface, []string) (string, error) {
b := make([]byte, 2)

rand.Read(b) //nolint:errcheck
Expand All @@ -20,6 +20,14 @@ func createPR(description, namespace string) func(github.GithubIface, []string)
branchName := namespace + "-rds-minor-version-bump-" + fourCharUid

return func(gh github.GithubIface, filenames []string) (string, error) {
removeRemoteCmd := exec.Command("/bin/sh", "-c", "git remote remove origin")
removeRemoteCmd.Start() //nolint:errcheck
removeRemoteCmd.Wait() //nolint:errcheck

useGhTokenCmd := exec.Command("/bin/sh", "-c", "git remote add origin https://"+ghToken+"@github.com/ministryofjustice/"+repo)
useGhTokenCmd.Start() //nolint:errcheck
useGhTokenCmd.Wait() //nolint:errcheck

checkCmd := exec.Command("/bin/sh", "-c", "git checkout -b "+branchName)
checkCmd.Start() //nolint:errcheck
checkCmd.Wait() //nolint:errcheck
Expand Down
2 changes: 1 addition & 1 deletion pkg/environment/environmentApply.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (a *Apply) applyTerraform() (string, error) {

description := "\n\n``` " + versionDescription + " ```\n\n" + a.Options.BuildUrl

prUrl, createErr := createPR(description, a.Options.Namespace)(a.GithubClient, filenames)
prUrl, createErr := createPR(description, a.Options.Namespace, a.Options.GithubToken, "cloud-platform-environments")(a.GithubClient, filenames)

if createErr != nil {
return "", fmt.Errorf("create error running terraform on namespace %s: %v \n %v \n %v", a.Options.Namespace, err, outputTerraform, createErr)
Expand Down

0 comments on commit 01e1450

Please sign in to comment.