update workflow

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2023-10-03 01:01:31 +03:00
parent 997ce8945f
commit 38bc8b8841

View File

@ -40,13 +40,14 @@ var (
type Config struct { type Config struct {
PullRequestTitle string `json:"pull_request_title" yaml:"pull_request_title"` PullRequestTitle string `json:"pull_request_title" yaml:"pull_request_title"`
PullRequestBody string `json:"pull_request_body" yaml:"pull_request_body"` PullRequestBody string `json:"pull_request_body" yaml:"pull_request_body"`
Branches []string `json:"branches" yaml:"branches"`
} }
var ( var (
configFiles = []string{ configFiles = []string{
"dependabot.yml", "dependabot.yml",
"pkgdash.yml", "pkgdashcli.yml",
"pkgdash.yaml", "pkgdashcli.yaml",
} }
configDirs = []string{ configDirs = []string{
".gitea", ".gitea",
@ -158,11 +159,12 @@ func main() {
logger.Fatalf(ctx, "failed to get repo management") logger.Fatalf(ctx, "failed to get repo management")
} }
branch := os.Getenv("GITHUB_REF_NAME")
switch repoMgmt { switch repoMgmt {
case "gitea": case "gitea":
for _, branch := range cfg.Branches {
err = giteaPullRequest(ctx, cfg, branch, mvs) err = giteaPullRequest(ctx, cfg, branch, mvs)
} }
}
if err != nil { if err != nil {
logger.Fatalf(ctx, "failed to create pr: %v", err) logger.Fatalf(ctx, "failed to create pr: %v", err)
@ -224,9 +226,25 @@ func giteaPullRequest(ctx context.Context, cfg *Config, branch string, mods map[
logger.Fatalf(ctx, "failed to fetch repo: %v", err) logger.Fatalf(ctx, "failed to fetch repo: %v", err)
} }
headRef, err := repo.Head() var headRef *plumbing.Reference
refIter, err := repo.Branches()
if err != nil { if err != nil {
logger.Fatalf(ctx, "failed to get repo head: %v", err) logger.Fatalf(ctx, "failed to get branches: %v", err)
}
for {
ref, err := refIter.Next()
if err != nil {
break
}
if ref.Name().String() == branch {
headRef = ref
break
}
}
refIter.Close()
if headRef == nil {
logger.Fatalf(ctx, "failed to get repo branch head")
} }
logger.Infof(ctx, "repo head %s", headRef) logger.Infof(ctx, "repo head %s", headRef)