Skip to content

Commit a081d20

Browse files
author
Feroze Mohideen
authored
change branch name (#4352)
1 parent 3ae6fac commit a081d20

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

api/server/handlers/porter_app/create_secret_and_open_pr.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/porter-dev/porter/api/server/shared/requestutils"
1616
"github.com/porter-dev/porter/api/types"
1717
"github.com/porter-dev/porter/internal/auth/token"
18+
"github.com/porter-dev/porter/internal/encryption"
1819
"github.com/porter-dev/porter/internal/integrations/ci/actions"
1920
"github.com/porter-dev/porter/internal/models"
2021
"github.com/porter-dev/porter/internal/telemetry"
@@ -117,6 +118,19 @@ func (c *OpenStackPRHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
117118
prRequestBody = "Hello 👋 from Porter! Please merge this PR to enable preview environments for your application."
118119
}
119120

121+
randStr, err := encryption.GenerateRandomBytes(4)
122+
if err != nil {
123+
err = telemetry.Error(ctx, span, err, "error generating random bytes")
124+
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
125+
return
126+
}
127+
128+
prBranchName := fmt.Sprintf("porter-stack-%s-%s", appName, randStr)
129+
// limit branch name to 100 characters for safety
130+
if len(prBranchName) > 100 {
131+
prBranchName = prBranchName[:100]
132+
}
133+
120134
if request.OpenPr || request.DeleteWorkflowFilename != "" {
121135
openPRInput := &actions.GithubPROpts{
122136
PRAction: actions.GithubPRAction_NewAppWorkflow,
@@ -131,7 +145,7 @@ func (c *OpenStackPRHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
131145
SecretName: secretName,
132146
PorterYamlPath: request.PorterYamlPath,
133147
Body: prRequestBody,
134-
PRBranch: "porter-stack",
148+
PRBranch: prBranchName,
135149
}
136150
if request.DeleteWorkflowFilename != "" {
137151
openPRInput.PRAction = actions.GithubPRAction_DeleteAppWorkflow

0 commit comments

Comments
 (0)