Resolve both branches and commit abbreviations

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-07-13 13:51:35 +03:00
parent 77aa221efe
commit 4d4511c407

11
main.go
View file

@ -38,8 +38,11 @@ func main() {
} }
// Limit number of iterations. // Limit number of iterations.
from := gha.GetInput("from")
log.Printf("Resolving revision '%s'", from)
var lca *object.Commit var lca *object.Commit
if from := gha.GetInput("from"); from != "" { if from != "" {
lca = getMergeBase(r, head, from) lca = getMergeBase(r, head, from)
} }
@ -75,6 +78,7 @@ func main() {
if !rxSignOff.MatchString(lines[len(lines)-1]) { if !rxSignOff.MatchString(lines[len(lines)-1]) {
fail = true fail = true
fmt.Printf("Error: missing sign-off %s [%s]\n", header, id) fmt.Printf("Error: missing sign-off %s [%s]\n", header, id)
return nil
} }
return nil return nil
@ -89,7 +93,10 @@ func main() {
func getMergeBase(r *git.Repository, head *plumbing.Reference, from string) *object.Commit { func getMergeBase(r *git.Repository, head *plumbing.Reference, from string) *object.Commit {
h, err := r.ResolveRevision(plumbing.Revision(from)) h, err := r.ResolveRevision(plumbing.Revision(from))
if err != nil { if err != nil {
log.Fatalf("Failed to resolve a reference: %v", err) h, err = r.ResolveRevision(plumbing.Revision(plumbing.NewBranchReferenceName(from)))
if err != nil {
log.Fatalf("Failed to resolve a reference '%s': %v", from, err)
}
} }
to, err := r.CommitObject(*h) to, err := r.CommitObject(*h)