summaryrefslogtreecommitdiff
path: root/windowNewPatchsets.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-23 04:47:21 -0500
committerJeff Carr <[email protected]>2025-03-23 04:47:21 -0500
commit682e06590ff1c3be43e734f48ee249864b69d4b3 (patch)
treebda80011f66ba4d642b5888ad4269da8ae55a70c /windowNewPatchsets.go
parentdd2f7ed01df0991f2d20669fbbd41a1c6d407805 (diff)
lookup the new hash for applied patches
Diffstat (limited to 'windowNewPatchsets.go')
-rw-r--r--windowNewPatchsets.go39
1 files changed, 29 insertions, 10 deletions
diff --git a/windowNewPatchsets.go b/windowNewPatchsets.go
index fced45d..92f5938 100644
--- a/windowNewPatchsets.go
+++ b/windowNewPatchsets.go
@@ -4,7 +4,10 @@
package main
import (
+ "bytes"
"fmt"
+ "os"
+ "os/exec"
"regexp"
"strings"
"sync"
@@ -116,12 +119,7 @@ func makePatchsetsWin() *stdPatchsetTableWin {
all := me.psets.All()
for all.Scan() {
pset := all.Next()
- if pset.State == "" {
- log.Info("What is up with?", pset.Name)
- setNewCommitHash(pset)
- } else {
- log.Info("patchset already had state", pset.Name, pset.State)
- }
+ setNewCommitHash(pset)
}
savePatchsets()
})
@@ -277,6 +275,24 @@ func cleanSubject(line string) string {
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) {
for patch := range p.Patches.IterAll() {
// 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)
continue
}
- log.Info("patch: not found hash:", patch.CommitHash, patch.RepoNamespace, comment)
- for dep := range repo.GoDeps.IterAll() {
- log.Info("dep:", dep.Name)
+ os.Chdir(repo.GetFullPath())
+ newhash, err := findCommitBySubject(comment)
+ 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)