lookup the new hash for applied patches
This commit is contained in:
parent
dd2f7ed01d
commit
682e06590f
|
@ -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 == "" {
|
setNewCommitHash(pset)
|
||||||
log.Info("What is up with?", pset.Name)
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue