lookup the new hash for applied patches

This commit is contained in:
Jeff Carr 2025-03-23 04:47:21 -05:00
parent dd2f7ed01d
commit 682e06590f
1 changed files with 29 additions and 10 deletions

View File

@ -4,7 +4,10 @@
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"os"
"os/exec"
"regexp" "regexp"
"strings" "strings"
"sync" "sync"
@ -116,12 +119,7 @@ func makePatchsetsWin() *stdPatchsetTableWin {
all := me.psets.All() all := me.psets.All()
for all.Scan() { for all.Scan() {
pset := all.Next() pset := all.Next()
if pset.State == "" {
log.Info("What is up with?", pset.Name)
setNewCommitHash(pset) setNewCommitHash(pset)
} else {
log.Info("patchset already had state", pset.Name, pset.State)
}
} }
savePatchsets() savePatchsets()
}) })
@ -277,6 +275,24 @@ func cleanSubject(line string) string {
return strings.TrimSpace(cleaned) return strings.TrimSpace(cleaned)
} }
func findCommitBySubject(subject string) (string, error) {
cmd := exec.Command("git", "log", "--pretty=format:%H %s", "--grep="+subject, "-i")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return "", err
}
lines := strings.Split(out.String(), "\n")
for _, line := range lines {
if strings.Contains(strings.ToLower(line), strings.ToLower(subject)) {
return strings.Fields(line)[0], nil // return the commit hash
}
}
return "", fmt.Errorf("no commit found for subject: %s", subject)
}
func setNewCommitHash(p *forgepb.Patchset) { func setNewCommitHash(p *forgepb.Patchset) {
for patch := range p.Patches.IterAll() { for patch := range p.Patches.IterAll() {
// parts := strings.Fields(patch.Comment) // parts := strings.Fields(patch.Comment)
@ -293,11 +309,14 @@ func setNewCommitHash(p *forgepb.Patchset) {
log.Info("patch: newhash:", patch.NewHash, "commithash:", patch.CommitHash, patch.RepoNamespace, comment) log.Info("patch: newhash:", patch.NewHash, "commithash:", patch.CommitHash, patch.RepoNamespace, comment)
continue continue
} }
log.Info("patch: not found hash:", patch.CommitHash, patch.RepoNamespace, comment) os.Chdir(repo.GetFullPath())
for dep := range repo.GoDeps.IterAll() { newhash, err := findCommitBySubject(comment)
log.Info("dep:", dep.Name) if err != nil {
log.Info("patch: not found hash:", patch.CommitHash, patch.RepoNamespace, comment, newhash, err)
continue
} }
return patch.NewHash = newhash
log.Info("patch: found hash:", patch.CommitHash, newhash, patch.RepoNamespace, comment)
/* /*
repo := me.forge.FindByGoPath(patch.RepoNamespace) repo := me.forge.FindByGoPath(patch.RepoNamespace)