Compare commits
3 Commits
949810709d
...
76aec3aabb
Author | SHA256 | Date | |
---|---|---|---|
76aec3aabb | |||
19fb7e277b | |||
51261f1bc1 |
58
common/manifest.go
Normal file
58
common/manifest.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Manifest struct {
|
||||
Subdirectories []string
|
||||
}
|
||||
|
||||
func (m *Manifest) SubdirForPackage(pkg string) string {
|
||||
if m == nil {
|
||||
return pkg
|
||||
}
|
||||
|
||||
idx := -1
|
||||
matchLen := 0
|
||||
lowercasePkg := strings.ToLower(pkg)
|
||||
|
||||
for i, sub := range m.Subdirectories {
|
||||
basename := strings.ToLower(strings.TrimSuffix(sub, "/"))
|
||||
if idx := strings.LastIndex(basename, "/"); idx > 0 {
|
||||
basename = basename[idx+1:]
|
||||
}
|
||||
if strings.HasPrefix(lowercasePkg, basename) && matchLen < len(basename) {
|
||||
idx = i
|
||||
matchLen = len(basename)
|
||||
}
|
||||
}
|
||||
|
||||
if idx > -1 {
|
||||
return path.Join(m.Subdirectories[idx], pkg)
|
||||
}
|
||||
return pkg
|
||||
}
|
||||
|
||||
func ReadManifestFile(filename string) (*Manifest, error) {
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ParseManifestFile(data)
|
||||
}
|
||||
|
||||
func ParseManifestFile(data []byte) (*Manifest, error) {
|
||||
ret := &Manifest{}
|
||||
err := yaml.Unmarshal(data, ret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
56
common/manifest_test.go
Normal file
56
common/manifest_test.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package common_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"src.opensuse.org/autogits/common"
|
||||
)
|
||||
|
||||
func TestManifestSubdirAssignments(t *testing.T) {
|
||||
tests := []struct {
|
||||
Name string
|
||||
ManifestContent string
|
||||
Packages []string
|
||||
ManifestLocations []string
|
||||
}{
|
||||
{
|
||||
Name: "empty manifest",
|
||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "boost", "NodeJS"},
|
||||
ManifestLocations: []string{"atom", "blarg", "Foobar", "X-Ray", "boost", "NodeJS"},
|
||||
},
|
||||
{
|
||||
Name: "only few subdirs manifest",
|
||||
ManifestContent: "subdirectories:\n - a\n - b",
|
||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "b/Boost", "NodeJS"},
|
||||
},
|
||||
{
|
||||
Name: "multilayer subdirs manifest",
|
||||
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo",
|
||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "NodeJS"},
|
||||
},
|
||||
{
|
||||
Name: "multilayer subdirs manifest with trailing /",
|
||||
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo/\n - somedir/Node/",
|
||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "somedir/Node/NodeJS"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
m, err := common.ParseManifestFile([]byte(test.ManifestContent))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, pkg := range test.Packages {
|
||||
expected := test.ManifestLocations[i]
|
||||
if l := m.SubdirForPackage(pkg); l != expected {
|
||||
t.Error("Expected:", expected, "but got:", l)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -25,6 +25,13 @@ type PRSet struct {
|
||||
BotUser string
|
||||
}
|
||||
|
||||
func (prinfo *PRInfo) PRComponents() (org string, repo string, idx int64) {
|
||||
org = prinfo.PR.Base.Repo.Owner.UserName
|
||||
repo = prinfo.PR.Base.Repo.Name
|
||||
idx = prinfo.PR.Index
|
||||
return
|
||||
}
|
||||
|
||||
func readPRData(gitea GiteaPRFetcher, pr *models.PullRequest, currentSet []*PRInfo, config *AutogitConfig) ([]*PRInfo, error) {
|
||||
for _, p := range currentSet {
|
||||
if pr.Index == p.PR.Index && pr.Base.Repo.Name == p.PR.Base.Repo.Name && pr.Base.Repo.Owner.UserName == p.PR.Base.Repo.Owner.UserName {
|
||||
|
@@ -190,10 +190,13 @@ func cloneDevel(git common.Git, gitDir, outName, urlString string) error {
|
||||
}
|
||||
|
||||
func importRepos(packages []string) {
|
||||
RepoToObsName := make(map[string]string)
|
||||
|
||||
factoryRepos := make([]*models.Repository, 0, len(packages)*2)
|
||||
develProjectPackages := make([]string, 0, len(packages))
|
||||
for _, pkg := range packages {
|
||||
src_pkg_name := strings.Split(pkg, ":")
|
||||
RepoToObsName[giteaPackage(src_pkg_name[0])] = src_pkg_name[0]
|
||||
repo, err := client.Repository.RepoGet(
|
||||
repository.NewRepoGetParams().
|
||||
WithDefaults().WithOwner("pool").WithRepo(giteaPackage(src_pkg_name[0])),
|
||||
@@ -223,7 +226,7 @@ func importRepos(packages []string) {
|
||||
|
||||
oldPackageNames := make([]string, 0, len(factoryRepos))
|
||||
for _, repo := range factoryRepos {
|
||||
oldPackageNames = append(oldPackageNames, repo.Name)
|
||||
oldPackageNames = append(oldPackageNames, RepoToObsName[repo.Name])
|
||||
}
|
||||
|
||||
// fork packags from pool
|
||||
@@ -245,40 +248,41 @@ func importRepos(packages []string) {
|
||||
log.Println("adding remotes...")
|
||||
for i := 0; i < len(factoryRepos); i++ {
|
||||
pkg := factoryRepos[i]
|
||||
pkgName := RepoToObsName[pkg.Name]
|
||||
|
||||
// verify that package was created by `git-importer`, or it's scmsync package and clone it
|
||||
fi, err := os.Stat(filepath.Join(git.GetPath(), pkg.Name))
|
||||
fi, err := os.Stat(filepath.Join(git.GetPath(), pkgName))
|
||||
if os.IsNotExist(err) {
|
||||
if slices.Contains(develProjectPackages, pkg.Name) {
|
||||
if slices.Contains(develProjectPackages, pkgName) {
|
||||
// failed import of former factory package
|
||||
continue
|
||||
}
|
||||
|
||||
// scmsync?
|
||||
devel_project, err := devel_projects.GetDevelProject(pkg.Name)
|
||||
devel_project, err := devel_projects.GetDevelProject(pkgName)
|
||||
if err != nil {
|
||||
log.Panicln("devel project not found for", pkg.Name, "err:", err)
|
||||
log.Panicln("devel project not found for", RepoToObsName[pkg.Name], "err:", err)
|
||||
}
|
||||
meta, _ := obs.GetPackageMeta(devel_project, pkg.Name)
|
||||
meta, _ := obs.GetPackageMeta(devel_project, pkgName)
|
||||
if len(meta.ScmSync) > 0 {
|
||||
if err2 := cloneDevel(git, "", pkg.Name, meta.ScmSync); err != nil {
|
||||
if err2 := cloneDevel(git, "", pkgName, meta.ScmSync); err != nil {
|
||||
log.Panicln(err2)
|
||||
}
|
||||
if err2 := git.GitExec(pkg.Name, "checkout", "-B", "main"); err2 != nil {
|
||||
git.GitExecOrPanic(pkg.Name, "checkout", "-B", "master")
|
||||
if err2 := git.GitExec(pkgName, "checkout", "-B", "main"); err2 != nil {
|
||||
git.GitExecOrPanic(pkgName, "checkout", "-B", "master")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// try again, should now exist
|
||||
if fi, err = os.Stat(filepath.Join(git.GetPath(), pkg.Name)); err != nil {
|
||||
if fi, err = os.Stat(filepath.Join(git.GetPath(), pkgName)); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
} else if err != nil {
|
||||
log.Panicln(err)
|
||||
} else {
|
||||
// verify that we do not have scmsync for imported packages
|
||||
meta, err := obs.GetPackageMeta(prj, pkg.Name)
|
||||
meta, err := obs.GetPackageMeta(prj, pkgName)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
@@ -288,13 +292,13 @@ func importRepos(packages []string) {
|
||||
if err != nil {
|
||||
log.Println("Invlid scmsync in", pkg, meta.ScmSync, err)
|
||||
}
|
||||
o, err := url.Parse(strings.TrimSpace(git.GitExecWithOutputOrPanic(pkg.Name, "remote", "get-url", "origin")))
|
||||
o, err := url.Parse(strings.TrimSpace(git.GitExecWithOutputOrPanic(pkgName, "remote", "get-url", "origin")))
|
||||
log.Println("Invlid scmsync in git repo", pkg, meta.ScmSync, err)
|
||||
if u.Host != o.Host || u.Path != u.Path {
|
||||
log.Panicln("importing an scmsync package??:", prj, pkg.Name)
|
||||
log.Panicln("importing an scmsync package??:", prj, pkgName)
|
||||
} else {
|
||||
log.Println("previous SCMSYNC package. Pull.")
|
||||
git.GitExecOrPanic(pkg.Name, "pull", "origin", "HEAD:main")
|
||||
git.GitExecOrPanic(pkgName, "pull", "origin", "HEAD:main")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,11 +308,11 @@ func importRepos(packages []string) {
|
||||
}
|
||||
|
||||
// add remote repos
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show", "-n")
|
||||
out := git.GitExecWithOutputOrPanic(pkgName, "remote", "show", "-n")
|
||||
switch pkg.Owner.UserName {
|
||||
case "pool":
|
||||
if !slices.Contains(strings.Split(out, "\n"), "pool") {
|
||||
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "add", "pool", pkg.CloneURL)
|
||||
out := git.GitExecWithOutputOrPanic(pkgName, "remote", "add", "pool", pkg.CloneURL)
|
||||
if len(strings.TrimSpace(out)) > 1 {
|
||||
log.Println(out)
|
||||
}
|
||||
@@ -422,11 +426,15 @@ func importRepos(packages []string) {
|
||||
log.Println("Error fetching pkg meta for:", prj, pkg, err)
|
||||
}
|
||||
}
|
||||
if len(meta.ScmSync) > 0 {
|
||||
if err2 := cloneDevel(git, "", pkg, meta.ScmSync); err2 != nil {
|
||||
log.Panicln(err2)
|
||||
if meta == nil {
|
||||
log.Println(" **** pkg meta is nil? ****")
|
||||
} else if len(meta.ScmSync) > 0 {
|
||||
if _, err := os.Stat(path.Join(git.GetPath(), pkg)); os.IsNotExist(err) {
|
||||
if err2 := cloneDevel(git, "", pkg, meta.ScmSync); err2 != nil {
|
||||
log.Panicln(err2)
|
||||
}
|
||||
git.GitExecOrPanic(pkg, "checkout", "-B", "main")
|
||||
}
|
||||
git.GitExecOrPanic(pkg, "checkout", "-B", "main")
|
||||
continue
|
||||
} else {
|
||||
common.PanicOnError(gitImporter(prj, pkg))
|
||||
@@ -467,11 +475,12 @@ func importRepos(packages []string) {
|
||||
|
||||
for _, pkg := range factoryRepos {
|
||||
var repo *models.Repository
|
||||
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(giteaPackage(pkg.Name)), r.DefaultAuthentication); err != nil {
|
||||
pkgName := RepoToObsName[pkg.Name]
|
||||
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(pkg.Name), r.DefaultAuthentication); err != nil {
|
||||
// update package
|
||||
fork, err := client.Repository.CreateFork(repository.NewCreateForkParams().
|
||||
WithOwner(pkg.Owner.UserName).
|
||||
WithRepo(giteaPackage(pkg.Name)).
|
||||
WithRepo(pkg.Name).
|
||||
WithBody(&models.CreateForkOption{
|
||||
Organization: org,
|
||||
}), r.DefaultAuthentication)
|
||||
@@ -485,18 +494,18 @@ func importRepos(packages []string) {
|
||||
}
|
||||
// branchName := repo.DefaultBranch
|
||||
|
||||
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show"), "\n")
|
||||
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkgName, "remote", "show"), "\n")
|
||||
if !slices.Contains(remotes, "develorigin") {
|
||||
git.GitExecOrPanic(pkg.Name, "remote", "add", "develorigin", repo.SSHURL)
|
||||
// git.GitExecOrPanic(pkg.Name, "fetch", "devel")
|
||||
git.GitExecOrPanic(pkgName, "remote", "add", "develorigin", repo.SSHURL)
|
||||
// git.GitExecOrPanic(pkgName, "fetch", "devel")
|
||||
}
|
||||
if slices.Contains(remotes, "origin") {
|
||||
git.GitExecOrPanic(pkg.Name, "lfs", "fetch", "--all")
|
||||
git.GitExecOrPanic(pkg.Name, "lfs", "push", "develorigin", "--all")
|
||||
git.GitExecOrPanic(pkgName, "lfs", "fetch", "--all")
|
||||
git.GitExecOrPanic(pkgName, "lfs", "push", "develorigin", "--all")
|
||||
}
|
||||
git.GitExecOrPanic(pkg.Name, "push", "develorigin", "main", "-f")
|
||||
git.GitExec(pkg.Name, "push", "develorigin", "--delete", "factory", "devel")
|
||||
// git.GitExecOrPanic(pkg.Name, "checkout", "-B", "main", "devel/main")
|
||||
git.GitExecOrPanic(pkgName, "push", "develorigin", "main", "-f")
|
||||
git.GitExec(pkgName, "push", "develorigin", "--delete", "factory", "devel")
|
||||
// git.GitExecOrPanic(pkg.ame, "checkout", "-B", "main", "devel/main")
|
||||
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(giteaPackage(repo.Name)).WithBody(&models.EditRepoOption{
|
||||
DefaultBranch: "main",
|
||||
DefaultMergeStyle: "fast-forward-only",
|
||||
@@ -881,6 +890,7 @@ func main() {
|
||||
syncMaintainers := flags.Bool("sync-maintainers-only", false, "Sync maintainers to Gitea and exit")
|
||||
flags.BoolVar(&forceBadPool, "bad-pool", false, "Force packages if pool has no branches due to bad import")
|
||||
flags.BoolVar(&forceNonPoolPackages, "non-pool", false, "Allow packages that are not in pool to be created. WARNING: Can't add to factory later!")
|
||||
specificPackage := flags.String("package", "", "Process specific package only, ignoring the others")
|
||||
|
||||
if help := flags.Parse(os.Args[1:]); help == flag.ErrHelp || flags.NArg() != 2 {
|
||||
printHelp(helpString.String())
|
||||
@@ -982,6 +992,10 @@ func main() {
|
||||
os.Exit(10)
|
||||
}
|
||||
|
||||
if len(*specificPackage) != 0 {
|
||||
importRepos([]string{*specificPackage})
|
||||
return
|
||||
}
|
||||
importRepos(packages)
|
||||
syncMaintainersToGitea(packages)
|
||||
}
|
||||
|
@@ -18,6 +18,33 @@ func prGitBranchNameForPR(repo string, prNo int) string {
|
||||
return fmt.Sprintf("PR_%s#%d", repo, prNo)
|
||||
}
|
||||
|
||||
func PrjGitDescription(prset *common.PRSet) (title string, desc string) {
|
||||
title_refs := make([]string, 0, len(prset.PRs)-1)
|
||||
refs := make([]string, 0, len(prset.PRs)-1)
|
||||
|
||||
for _, pr := range prset.PRs {
|
||||
org, repo, idx := pr.PRComponents()
|
||||
|
||||
title_refs = append(title_refs, repo)
|
||||
ref := fmt.Sprintf(common.PrPattern, org, repo, idx)
|
||||
refs = append(refs, ref)
|
||||
}
|
||||
|
||||
title = "Forwarded PRs: " + strings.Join(title_refs, ", ")
|
||||
desc = fmt.Sprintf("This is a forwarded pull request by %s\nreferencing the following pull request(s):\n\n", GitAuthor) + strings.Join(refs, ",\n")
|
||||
|
||||
if prset.Config.ManualMergeOnly {
|
||||
desc = desc + "\n\nManualMergeOnly enabled. To merge, 'merge ok' is required in either the project PR or every package PR."
|
||||
}
|
||||
if prset.Config.ManualMergeProject {
|
||||
desc = desc + "\nManualMergeProject enabled. To merge, 'merge ok' is required by project maintainer in the project PR."
|
||||
}
|
||||
if !prset.Config.ManualMergeOnly && !prset.Config.ManualMergeProject {
|
||||
desc = desc + "\nAutomatic merge enabled. This will merge when all review requirements are satisfied."
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func verifyRepositoryConfiguration(repo *models.Repository) error {
|
||||
if repo.AutodetectManualMerge && repo.AllowManualMerge {
|
||||
return nil
|
||||
@@ -90,24 +117,20 @@ func AllocatePRProcessor(req *common.PullRequestWebhookEvent, configs common.Aut
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) ([]string, []string, error) {
|
||||
func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) error {
|
||||
git := pr.git
|
||||
subList, err := git.GitSubmoduleList(common.DefaultGitPrj, "HEAD")
|
||||
if err != nil {
|
||||
common.LogError("Error fetching submodule list for PrjGit", err)
|
||||
return nil, nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
refs := make([]string, 0, len(prset.PRs))
|
||||
title_refs := make([]string, 0, len(prset.PRs))
|
||||
for _, pr := range prset.PRs {
|
||||
if prset.IsPrjGitPR(pr.PR) {
|
||||
continue
|
||||
}
|
||||
|
||||
org := pr.PR.Base.Repo.Owner.UserName
|
||||
repo := pr.PR.Base.Repo.Name
|
||||
idx := pr.PR.Index
|
||||
org, repo, idx := pr.PRComponents()
|
||||
prHead := pr.PR.Head.Sha
|
||||
revert := false
|
||||
|
||||
@@ -118,7 +141,7 @@ func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) ([]string,
|
||||
var valid bool
|
||||
if prHead, valid = git.GitSubmoduleCommitId(common.DefaultGitPrj, repo, prjGitPR.PR.MergeBase); !valid {
|
||||
common.LogError("Failed fetching original submodule commit id for repo")
|
||||
return nil, nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
revert = true
|
||||
@@ -135,9 +158,6 @@ func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) ([]string,
|
||||
|
||||
if revert {
|
||||
commitMsg = fmt.Sprintln("auto-created for", repo, "\n\nThis commit was autocreated by", GitAuthor, "removing\n", ref)
|
||||
} else {
|
||||
refs = append(refs, ref)
|
||||
title_refs = append(title_refs, repo)
|
||||
}
|
||||
|
||||
updateSubmoduleInPR(submodulePath, prHead, git)
|
||||
@@ -156,7 +176,7 @@ func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) ([]string,
|
||||
common.LogError("Failed to find expected repo:", repo)
|
||||
}
|
||||
}
|
||||
return title_refs, refs, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pr *PRProcessor) CreatePRjGitPR(prjGitPRbranch string, prset *common.PRSet) error {
|
||||
@@ -176,8 +196,7 @@ func (pr *PRProcessor) CreatePRjGitPR(prjGitPRbranch string, prset *common.PRSet
|
||||
common.LogError("Failed to fetch PrjGit branch", prjGitPRbranch, err)
|
||||
return err
|
||||
}
|
||||
title_refs, refs, err := pr.SetSubmodulesToMatchPRSet(prset)
|
||||
if err != nil {
|
||||
if err := pr.SetSubmodulesToMatchPRSet(prset); err != nil {
|
||||
return err
|
||||
}
|
||||
newHeadCommit, err := git.GitBranchHead(common.DefaultGitPrj, prjGitPRbranch)
|
||||
@@ -188,10 +207,8 @@ func (pr *PRProcessor) CreatePRjGitPR(prjGitPRbranch string, prset *common.PRSet
|
||||
|
||||
if !common.IsDryRun && headCommit != newHeadCommit {
|
||||
common.PanicOnError(git.GitExec(common.DefaultGitPrj, "push", RemoteName, "+HEAD:"+prjGitPRbranch))
|
||||
pr, err := Gitea.CreatePullRequestIfNotExist(PrjGit, prjGitPRbranch, PrjGitBranch,
|
||||
"Forwarded PRs: "+strings.Join(title_refs, ", "),
|
||||
fmt.Sprintf("This is a forwarded pull request by %s\nreferencing the following pull request(s):\n\n", GitAuthor)+strings.Join(refs, ", "),
|
||||
)
|
||||
title, desc := PrjGitDescription(prset)
|
||||
pr, err := Gitea.CreatePullRequestIfNotExist(PrjGit, prjGitPRbranch, PrjGitBranch, title, desc)
|
||||
if err != nil {
|
||||
common.LogError("Error creating PrjGit PR:", err)
|
||||
return err
|
||||
@@ -247,10 +264,10 @@ func (pr *PRProcessor) UpdatePrjGitPR(prset *common.PRSet) error {
|
||||
PrjGitPR.RemoteName, err = git.GitClone(common.DefaultGitPrj, prjGitPRbranch, PrjGit.SSHURL)
|
||||
common.PanicOnError(err)
|
||||
git.GitExecOrPanic(common.DefaultGitPrj, "fetch", PrjGitPR.RemoteName, PrjGitBranch)
|
||||
ExpectedMergeCommit, err := git.GitRemoteHead(common.DefaultGitPrj, PrjGitPR.RemoteName, PrjGitBranch)
|
||||
|
||||
forcePush := false
|
||||
if ExpectedMergeCommit != PrjGitPR.PR.MergeBase {
|
||||
// trust Gitea here on mergeability
|
||||
if !PrjGitPR.PR.Mergeable {
|
||||
common.PanicOnError(pr.RebaseAndSkipSubmoduleCommits(prset, PrjGitBranch))
|
||||
forcePush = true
|
||||
}
|
||||
@@ -260,8 +277,7 @@ func (pr *PRProcessor) UpdatePrjGitPR(prset *common.PRSet) error {
|
||||
common.LogError("Failed to fetch PrjGit branch", prjGitPRbranch, err)
|
||||
return err
|
||||
}
|
||||
title_refs, refs, err := pr.SetSubmodulesToMatchPRSet(prset)
|
||||
if err != nil {
|
||||
if err := pr.SetSubmodulesToMatchPRSet(prset); err != nil {
|
||||
return err
|
||||
}
|
||||
newHeadCommit, err := git.GitBranchHead(common.DefaultGitPrj, prjGitPRbranch)
|
||||
@@ -278,9 +294,7 @@ func (pr *PRProcessor) UpdatePrjGitPR(prset *common.PRSet) error {
|
||||
common.PanicOnError(git.GitExec(common.DefaultGitPrj, params...))
|
||||
|
||||
// update PR
|
||||
PrjGitTitle := "Forwarded PRs: " + strings.Join(title_refs, ", ")
|
||||
PrjGitBody := fmt.Sprintf("This is a forwarded pull request by %s\nreferencing the following pull request(s):\n\n", GitAuthor) + strings.Join(refs, ", ")
|
||||
|
||||
PrjGitTitle, PrjGitBody := PrjGitDescription(prset)
|
||||
Gitea.UpdatePullRequest(PrjGit.Owner.UserName, PrjGit.Name, PrjGitPR.PR.Index, &models.EditPullRequestOption{
|
||||
RemoveDeadline: true,
|
||||
Title: PrjGitTitle,
|
||||
@@ -326,9 +340,7 @@ func (pr *PRProcessor) Process(req *common.PullRequestWebhookEvent) error {
|
||||
common.LogInfo("PR State is closed:", prjGitPR.PR.State)
|
||||
for _, pr := range prset.PRs {
|
||||
if pr.PR.State == "open" {
|
||||
org := pr.PR.Base.Repo.Owner.UserName
|
||||
repo := pr.PR.Base.Repo.Name
|
||||
idx := pr.PR.Index
|
||||
org, repo, idx := pr.PRComponents()
|
||||
Gitea.UpdatePullRequest(org, repo, idx, &models.EditPullRequestOption{
|
||||
State: "closed",
|
||||
})
|
||||
@@ -337,6 +349,14 @@ func (pr *PRProcessor) Process(req *common.PullRequestWebhookEvent) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(prset.PRs) > 1 {
|
||||
for _, pr := range prset.PRs {
|
||||
if prset.IsPrjGitPR(pr.PR) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err = pr.UpdatePrjGitPR(prset); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user