Monorepo for Tangled tangled.org

hooks: add create PR message on git push #612

Respond to a successful push with a URL to create a PR pointing to the default branch. This behavior is made to mimic other Git forges.

Signed-off-by: Samuel Shuert me@thecoded.prof

Labels
enhancement
assignee

None yet.

Participants 2
AT URI
at://did:plc:k2zmz2l3hvfr44tmlhewol2j/sh.tangled.repo.pull/3lzwhi232k322
+3 -2
Interdiff #3 โ†’ #4
+3 -2
knotserver/internal.go
··· 13 13 securejoin "github.com/cyphar/filepath-securejoin" 14 14 "github.com/go-chi/chi/v5" 15 15 "github.com/go-chi/chi/v5/middleware" 16 + "github.com/go-git/go-git/v5/plumbing" 16 17 "tangled.org/core/api/tangled" 17 18 "tangled.org/core/hook" 18 19 "tangled.org/core/idresolver" ··· 161 162 l.Error("Failed to fetch default branch", "err", err) 162 163 return []string{}, err 163 164 } 164 - if line.Ref == fmt.Sprintf("refs/heads/%s", defaultBranch) { 165 + if line.Ref == plumbing.NewBranchReferenceName(defaultBranch).String() { 165 166 return []string{}, nil 166 167 } 167 - ZWS := "โ€‹" 168 + ZWS := "\u200B" 168 169 var msg []string 169 170 msg = append(msg, ZWS) 170 171 msg = append(msg, fmt.Sprintf("Create a PR pointing to %s", defaultBranch))

History

5 rounds 3 comments
sign up or login to add to the discussion
1 commit
expand
knotserver/internal: add create PR message on git push
expand 1 comment

lgtm thanks!

pull request successfully merged
1 commit
expand
knotserver/internal: add create PR message on git push
expand 0 comments
1 commit
expand
knotserver/internal: add create PR message on git push
expand 0 comments
1 commit
expand
knotserver: add create PR message on git push
expand 1 comment

this looks pretty good now! the only thing i'd want from this is for this handler to be separated out, just like how insertRefUpdate and triggerPipeline are split up.

this is because we don't want errors here to end the function, even the userIdent fails to resolve, we want to continue with the rest of the post-receive handler.

1 commit
expand
hooks: add create PR message on git push
expand 1 comment

i would prefer if this addition were made to knotserver/internal.go along side the other post-recieve handlers (insertRefUpdate and triggerPipeline). the way to return strings to the user in this handler are via the HookResponse struct.

there is an example of this in triggerPipeline which conditionally returns pipeline compilation status back to the user, by writing messages into resp.Messages. we could do something similar here.

that being said, the change largely looks good to me! thanks for working on this.