lookup the new hash for applied patches
This commit is contained in:
parent
dd2f7ed01d
commit
682e06590f
|
@ -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)
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue