gofmt lint errors fixes ... a lot of
gofmt / Format checking (pull_request) Failing after 4s
go-generate-check / go-generate-check (pull_request) Successful in 14s
gofmt / Linter and static analysis (pull_request) Successful in 1m8s
go-test-unit / go-test-unit (pull_request) Failing after 1m10s
Integration (Selective) / check (pull_request) Successful in 2s
Integration (Selective) / integration (pull_request) Successful in 9m5s
gofmt / Format checking (pull_request) Failing after 4s
go-generate-check / go-generate-check (pull_request) Successful in 14s
gofmt / Linter and static analysis (pull_request) Successful in 1m8s
go-test-unit / go-test-unit (pull_request) Failing after 1m10s
Integration (Selective) / check (pull_request) Successful in 2s
Integration (Selective) / integration (pull_request) Successful in 9m5s
This commit is contained in:
+2
-2
@@ -88,7 +88,7 @@ func (d *Debouncer) Requeue(ctx context.Context, req *Request) error {
|
||||
|
||||
delay := d.coolOffPeriod
|
||||
if task, exists := d.pending[key]; exists {
|
||||
delay = task.currentDelay * 2
|
||||
delay = task.currentDelay * 2 //nolint:mnd
|
||||
}
|
||||
d.mu.Unlock()
|
||||
|
||||
@@ -123,7 +123,7 @@ func (d *Debouncer) processWithDelay(ctx context.Context, req *Request, delay ti
|
||||
d.mu.Lock()
|
||||
if currentTask, exists := d.pending[key]; exists && currentTask == task {
|
||||
d.mu.Unlock()
|
||||
d.Requeue(ctx, req)
|
||||
_ = d.Requeue(ctx, req)
|
||||
} else {
|
||||
d.mu.Unlock()
|
||||
}
|
||||
|
||||
+6
-6
@@ -205,7 +205,7 @@ func (s *gitHandlerGeneratorImpl) CreateGitHandlerCtx(ctx context.Context, confi
|
||||
orgLock.Unlock()
|
||||
return nil, err
|
||||
} else if err != nil && os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(orgPath, 0o777); err != nil && !os.IsExist(err) {
|
||||
if err := os.MkdirAll(orgPath, 0o777); err != nil && !os.IsExist(err) { //nolint:mnd
|
||||
orgLock.Unlock()
|
||||
return nil, err
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func (s *gitHandlerGeneratorImpl) CreateGitHandler(config *AutogitConfig) (Git,
|
||||
|
||||
func (s *gitHandlerGeneratorImpl) ReadExistingPathWithPrjCtx(ctx context.Context, org, prjPath string) (Git, error) {
|
||||
if prjPath == "" {
|
||||
return nil, fmt.Errorf("Project path is required")
|
||||
return nil, fmt.Errorf("project path is required")
|
||||
}
|
||||
s.lock_lock.Lock()
|
||||
|
||||
@@ -324,7 +324,7 @@ func (e *GitHandlerImpl) GitClone(repo, branch, remoteUrl string) (string, error
|
||||
if _, err := os.Stat(path.Join(fullRepoPath, ".git")); os.IsNotExist(err) {
|
||||
p := path.Dir(fullRepoPath)
|
||||
if _, err := os.Stat(p); errors.Is(err, os.ErrNotExist) {
|
||||
if err = os.MkdirAll(p, 0o777); err != nil {
|
||||
if err = os.MkdirAll(p, 0o777); err != nil { //nolint:mnd
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
@@ -388,7 +388,7 @@ func (e *GitHandlerImpl) GitCloneLocal(gitDir, repoPath string) (remoteName stri
|
||||
fullPath := path.Join(e.GetPath(), gitDir)
|
||||
|
||||
if _, err := os.Stat(path.Join(fullPath, ".git")); errors.Is(err, os.ErrNotExist) {
|
||||
os.RemoveAll(path.Join(e.GetPath(), gitDir))
|
||||
_ = os.RemoveAll(path.Join(e.GetPath(), gitDir))
|
||||
LogDebugCtx(e.ctx, "Cloning repo:", repoPath, " -> ", gitDir)
|
||||
e._gitExec(e.GetPath(), "clone", "-o", remoteName, repoPath, gitDir) //nolint:errcheck
|
||||
} else {
|
||||
@@ -543,7 +543,7 @@ func (e *GitHandlerImpl) GitExecWithOutput(cwd string, params ...string) (string
|
||||
}
|
||||
allowed := strings.HasPrefix(Dir, basePath)
|
||||
if !filepath.IsAbs(Dir) || !allowed {
|
||||
return "", fmt.Errorf("Invalid execution path")
|
||||
return "", fmt.Errorf("invalid execution path")
|
||||
}
|
||||
|
||||
return e._gitExec(Dir, params...)
|
||||
@@ -707,7 +707,7 @@ func (e *GitHandlerImpl) GitListConfiguredSubmodules(cwd string) (Submodules, er
|
||||
}
|
||||
if err != nil {
|
||||
LogErrorCtx(e.ctx, "Cannot read .gitmodules:", err)
|
||||
return Submodules{}, fmt.Errorf("Cannot read .gitmodules file: %v", err)
|
||||
return Submodules{}, fmt.Errorf("cannot read .gitmodules file: %v", err)
|
||||
}
|
||||
|
||||
return ParseSubmodulesFile(bytes.NewReader(data))
|
||||
|
||||
@@ -740,7 +740,7 @@ func (gitea *GiteaTransport) GetOrganizationRepositories(orgName string) ([]*mod
|
||||
|
||||
func (gitea *GiteaTransport) GetUserRepositories(username string) ([]*models.Repository, error) {
|
||||
var page int64
|
||||
repos := make([]*models.Repository, 0, 100)
|
||||
repos := make([]*models.Repository, 0, 100) //nolint:mnd
|
||||
|
||||
page = 1
|
||||
for {
|
||||
@@ -1164,7 +1164,7 @@ func (gitea *GiteaTransport) GetOpenPullRequests(org, repo, branch string) ([]*m
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) GetPullRequestsWithState(org, repo, state string) ([]*models.PullRequest, error) {
|
||||
prs := make([]*models.PullRequest, 0, 50)
|
||||
prs := make([]*models.PullRequest, 0, 50) //nolint:mnd
|
||||
var page int64 = 1
|
||||
sort := "recentupdate"
|
||||
|
||||
@@ -1193,7 +1193,7 @@ func (gitea *GiteaTransport) GetPullRequestsWithState(org, repo, state string) (
|
||||
}
|
||||
|
||||
func (gitea *GiteaTransport) ListBranches(org, repo string) ([]*models.Branch, error) {
|
||||
branches := make([]*models.Branch, 0, 50)
|
||||
branches := make([]*models.Branch, 0, 50) //nolint:mnd
|
||||
var page int64 = 1
|
||||
|
||||
for {
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ func TaskRefPush(org, repo, ref string) string {
|
||||
}
|
||||
|
||||
func TaskRefStatus(org, repo, context, sha string) string {
|
||||
if len(sha) > 8 {
|
||||
if len(sha) > 8 { //nolint:mnd
|
||||
sha = sha[:8]
|
||||
}
|
||||
return fmt.Sprintf("%s/%s:%s@%s", org, repo, context, sha)
|
||||
|
||||
@@ -122,12 +122,13 @@ func SetupLoggerMocks(m any) {
|
||||
callV := m.Call(in)[0]
|
||||
|
||||
// Set return value if needed
|
||||
if name == "WithContext" {
|
||||
switch name {
|
||||
case "WithContext":
|
||||
retM := callV.MethodByName("Return")
|
||||
if retM.IsValid() {
|
||||
callV = retM.Call([]reflect.Value{v})[0]
|
||||
}
|
||||
} else if name == "Context" {
|
||||
case "Context":
|
||||
retM := callV.MethodByName("Return")
|
||||
if retM.IsValid() {
|
||||
callV = retM.Call([]reflect.Value{reflect.ValueOf(context.TODO())})[0]
|
||||
|
||||
+1
-1
@@ -738,7 +738,7 @@ func (rs *PRSet) PrepareForMerge(git Git) error {
|
||||
repo := prinfo.PR.Base.Repo
|
||||
head := prinfo.PR.Head
|
||||
if repo == nil || head == nil || head.Repo == nil {
|
||||
return fmt.Errorf("Incomplete PR data for %s", PRtoString(prinfo.PR))
|
||||
return fmt.Errorf("incomplete PR data for %s", PRtoString(prinfo.PR))
|
||||
}
|
||||
br := rs.Config.Branch
|
||||
if len(br) == 0 {
|
||||
|
||||
+4
-4
@@ -111,11 +111,11 @@ func (l *RabbitConnection) ProcessRabbitMQ(msgCh chan<- RabbitMessage) error {
|
||||
if l.ch.IsClosed() {
|
||||
l.ch, err = connection.Channel()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Channel cannot be re-opened for exchange check. Err: %w", err)
|
||||
return fmt.Errorf("channel cannot be re-opened for exchange check: %w", err)
|
||||
}
|
||||
}
|
||||
if err = l.ch.ExchangeDeclarePassive(exchange, "topic", true, false, false, false, nil); err != nil {
|
||||
return fmt.Errorf("Cannot declare exchange %s? Err: %w", exchange, err)
|
||||
return fmt.Errorf("cannot declare exchange %s: %w", exchange, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func (l *RabbitConnection) ProcessRabbitMQ(msgCh chan<- RabbitMessage) error {
|
||||
if l.ch.IsClosed() {
|
||||
l.ch, err = connection.Channel()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Channel cannot be re-opened. Err: %w", err)
|
||||
return fmt.Errorf("channel cannot be re-opened: %w", err)
|
||||
}
|
||||
}
|
||||
q, err = l.ch.QueueDeclare(queueName, true, false, false, false, nil)
|
||||
@@ -140,7 +140,7 @@ func (l *RabbitConnection) ProcessRabbitMQ(msgCh chan<- RabbitMessage) error {
|
||||
var chErr error
|
||||
l.ch, chErr = connection.Channel()
|
||||
if chErr != nil {
|
||||
return fmt.Errorf("Channel cannot be re-opened. Err: %w", chErr)
|
||||
return fmt.Errorf("channel cannot be re-opened: %w", chErr)
|
||||
}
|
||||
}
|
||||
q, err = l.ch.QueueDeclare("", false, true, true, false, nil)
|
||||
|
||||
@@ -860,7 +860,7 @@ func syncMaintainersToGitea(pkgs []string) {
|
||||
git.GitExecOrPanic(common.DefaultGitPrj, "push")
|
||||
}
|
||||
}
|
||||
if l := len(strings.Fields(git.GitExecWithOutputOrPanic(common.DefaultGitPrj, "status", "--porcelain=2"))); l > 0 {
|
||||
if l := len(strings.Fields(git.GitExecWithOutputOrPanic(common.DefaultGitPrj, "status", "--porcelain=2"))); l > 0 { //nolint:staticcheck
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1020,7 +1020,7 @@ func main() {
|
||||
packages = TrimMultibuildPackages(packages)
|
||||
|
||||
orgPath := path.Join(basePath, org)
|
||||
if err := os.MkdirAll(orgPath, 0o777); err != nil {
|
||||
if err := os.MkdirAll(orgPath, 0o777); err != nil { //nolint:mnd
|
||||
log.Panicln("Cannot create org directory", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ func ConnectToExchangeForPublish(host, username, password string) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) //nolint:mnd
|
||||
defer cancel()
|
||||
|
||||
if DebugMode {
|
||||
|
||||
@@ -332,7 +332,7 @@ func (bot *ReviewBot) ProcessPR(ctx context.Context, pr *models.PullRequest) err
|
||||
helpComment = helpComment + "\n\n" +
|
||||
"Submitter is member of this review group, hence they are excluded from being one of the reviewers here"
|
||||
}
|
||||
bot.gitea.WithContext(ctx).AddComment(pr, helpComment)
|
||||
_ = bot.gitea.WithContext(ctx).AddComment(pr, helpComment)
|
||||
}
|
||||
|
||||
return ReviewNotFinished
|
||||
|
||||
@@ -33,7 +33,7 @@ func (s *IssueCommentProcessor) ProcessFunc(ctx context.Context, req *common.Req
|
||||
common.LogInfoCtx(ctx, "[amqp] processing")
|
||||
pr, err := s.bot.gitea.WithContext(ctx).GetPullRequest(org, repo, index)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to fetch PullRequest from event: %s Error: %w", common.TaskRefPR(org, repo, index), err)
|
||||
return fmt.Errorf("failed to fetch PullRequest from event: %s, error: %w", common.TaskRefPR(org, repo, index), err)
|
||||
}
|
||||
return s.bot.ProcessPR(ctx, pr)
|
||||
}
|
||||
|
||||
@@ -688,7 +688,7 @@ func ProcessPullNotification(obs common.ObsClientInterface, gitea common.Gitea,
|
||||
if err != nil {
|
||||
common.LogDebug("Skipping non-PR notification:", err.Error())
|
||||
if !IsDryRun {
|
||||
gitea.SetNotificationRead(thread.ID)
|
||||
_ = gitea.SetNotificationRead(thread.ID)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -699,7 +699,7 @@ func ProcessPullNotification(obs common.ObsClientInterface, gitea common.Gitea,
|
||||
|
||||
done, err := ProcessPullRequest(ctx, obs, gitea, org, repo, num)
|
||||
if !IsDryRun && err == nil && done {
|
||||
gitea.WithContext(ctx).SetNotificationRead(thread.ID)
|
||||
_ = gitea.WithContext(ctx).SetNotificationRead(thread.ID)
|
||||
} else if err != nil {
|
||||
common.LogErrorCtx(ctx, err)
|
||||
}
|
||||
@@ -917,7 +917,7 @@ func ProcessPullRequest(ctx context.Context, obs common.ObsClientInterface, gite
|
||||
common.PanicOnError(err)
|
||||
|
||||
orgPath := path.Join(dir, org)
|
||||
if err := os.MkdirAll(orgPath, 0700); err != nil {
|
||||
if err := os.MkdirAll(orgPath, 0700); err != nil { //nolint:mnd
|
||||
return true, err
|
||||
}
|
||||
|
||||
@@ -1154,7 +1154,7 @@ func ProcessPullRequest(ctx context.Context, obs common.ObsClientInterface, gite
|
||||
status.State = common.CommitStatus_Fail
|
||||
common.LogErrorCtx(ctx, msg)
|
||||
if !IsDryRun {
|
||||
SetStatus(gitea.WithContext(ctx), org, repo, pr.Head.Sha, status)
|
||||
_ = SetStatus(gitea.WithContext(ctx), org, repo, pr.Head.Sha, status)
|
||||
_, err = gitea.WithContext(ctx).AddReviewComment(pr, common.ReviewStateRequestChanges, msg)
|
||||
if err != nil {
|
||||
common.LogErrorCtx(ctx, err)
|
||||
@@ -1170,7 +1170,7 @@ func ProcessPullRequest(ctx context.Context, obs common.ObsClientInterface, gite
|
||||
msg = "Build is started in " + ObsWebHost + "/project/show/" +
|
||||
stagingProject + " .\n"
|
||||
|
||||
SetStatus(gitea.WithContext(ctx), org, repo, pr.Head.Sha, status)
|
||||
_ = SetStatus(gitea.WithContext(ctx), org, repo, pr.Head.Sha, status)
|
||||
}
|
||||
|
||||
stagingResult, err := obs.BuildStatus(stagingProject)
|
||||
@@ -1232,7 +1232,7 @@ func ProcessPullRequest(ctx context.Context, obs common.ObsClientInterface, gite
|
||||
// and change commit state to fail
|
||||
status.State = common.CommitStatus_Fail
|
||||
status.TargetURL = ObsWebHost + "/project/show/" + qaProject
|
||||
SetStatus(gitea.WithContext(ctx), org, repo, pr.Head.Sha, status)
|
||||
_ = SetStatus(gitea.WithContext(ctx), org, repo, pr.Head.Sha, status)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1495,7 +1495,7 @@ func main() {
|
||||
id, _ := strconv.ParseInt(m[3], 10, 64)
|
||||
|
||||
ctx := common.ContextWithPR(context.TODO(), m[1], m[2], id)
|
||||
ProcessPullRequest(ctx, ObsClient, gitea, m[1], m[2], id)
|
||||
_, _ = ProcessPullRequest(ctx, ObsClient, gitea, m[1], m[2], id)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ func (s *CleanupService) IdentifyCandidates(ctx context.Context, opts CleanupOpt
|
||||
|
||||
// Validate prefixes: must be at least 3 characters and end with a non-alphanumeric character
|
||||
for _, prefix := range activePrefixes {
|
||||
if len(prefix) < 3 {
|
||||
if len(prefix) < 3 { //nolint:mnd
|
||||
return nil, fmt.Errorf("invalid prefix '%s': must be at least 3 characters long", prefix)
|
||||
}
|
||||
lastChar := prefix[len(prefix)-1]
|
||||
@@ -217,7 +217,7 @@ func (s *CleanupService) Run(ctx context.Context, opts CleanupOptions) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create temporary directory: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer os.RemoveAll(tempDir) //nolint:errcheck
|
||||
|
||||
// Fetch repository info to build authenticated URL and check object format
|
||||
repoInfo, err := s.Gitea.GetRepository(opts.Owner, opts.Repo)
|
||||
|
||||
@@ -51,8 +51,8 @@ func main() {
|
||||
org := flag.String("org", "", "Organization or owner of the repository")
|
||||
repo := flag.String("repo", "", "Repository name")
|
||||
prefix := flag.String("prefix", "", "Branch prefix or comma-separated prefixes to delete")
|
||||
inactivityDays := flag.Int("inactivity-days", 30, "Number of days of inactivity to consider a branch stale (single-run mode)")
|
||||
batchSize := flag.Int("batch", 25, "Maximum number of branches to delete in a single push command")
|
||||
inactivityDays := flag.Int("inactivity-days", 30, "Number of days of inactivity to consider a branch stale (single-run mode)") //nolint:mnd
|
||||
batchSize := flag.Int("batch", 25, "Maximum number of branches to delete in a single push command") //nolint:mnd
|
||||
dryRun := flag.Bool("dry-run", true, "Perform a dry-run and print git push command without executing")
|
||||
remote := flag.String("remote", common.DefaultGitRemote, "The git remote to target for branch deletion")
|
||||
repoPath := flag.String("repo-path", "", "The repository path where the local clone is stored")
|
||||
@@ -108,9 +108,9 @@ func main() {
|
||||
|
||||
var repoInactivityDays int
|
||||
if explicitFlags["inactivity-days"] {
|
||||
repoInactivityDays = resolveInactivityDaysPointer(inactivityDays, 30)
|
||||
repoInactivityDays = resolveInactivityDaysPointer(inactivityDays, 30) //nolint:mnd
|
||||
} else {
|
||||
repoInactivityDays = resolveInactivityDaysPointer(cfg.InactivityDays, 30)
|
||||
repoInactivityDays = resolveInactivityDaysPointer(cfg.InactivityDays, 30) //nolint:mnd
|
||||
}
|
||||
|
||||
repoBatchSize := *batchSize
|
||||
@@ -239,7 +239,7 @@ func main() {
|
||||
Owner: *org,
|
||||
Repo: repoName,
|
||||
Prefixes: prefixes,
|
||||
InactivityDays: resolveInactivityDaysPointer(inactivityDays, 30),
|
||||
InactivityDays: resolveInactivityDaysPointer(inactivityDays, 30), //nolint:mnd
|
||||
BatchSize: *batchSize,
|
||||
DryRun: *dryRun,
|
||||
Remote: *remote,
|
||||
@@ -271,7 +271,7 @@ func runConfigOnce(ctx context.Context, cfg Config, filterOrg string, filterRepo
|
||||
cleanupService := NewCleanupService(giteaClient)
|
||||
|
||||
// Default values if not specified per repo
|
||||
globalInactivityDays := resolveInactivityDaysPointer(cfg.InactivityDays, 30)
|
||||
globalInactivityDays := resolveInactivityDaysPointer(cfg.InactivityDays, 30) //nolint:mnd
|
||||
globalBatchSize := cfg.BatchSize
|
||||
if globalBatchSize <= 0 {
|
||||
globalBatchSize = 25
|
||||
|
||||
@@ -466,7 +466,7 @@ next_package:
|
||||
continue
|
||||
}
|
||||
|
||||
commits, err := gitea.WithContext(ctx).GetRecentCommits(org, repoName, branch, 10)
|
||||
commits, err := gitea.WithContext(ctx).GetRecentCommits(org, repoName, branch, 10) //nolint:mnd
|
||||
if err != nil {
|
||||
common.LogDebugCtx(ctx, " -> failed to fetch recent commits for package:", filename, " Err:", err)
|
||||
continue
|
||||
@@ -741,7 +741,7 @@ func main() {
|
||||
flag.BoolVar(&checkOnStart, "check-on-start", false, "Check all repositories for consistency on start, without delays")
|
||||
checkIntervalHours := flag.Float64("check-interval", common.DefaultCheckIntervalHours, "Check interval (+-random delay) for repositories for consistency, in hours")
|
||||
basePath := flag.String("repo-path", os.Getenv("AUTOGITS_REPO_PATH"), "Repository path. Default is temporary directory")
|
||||
debounceDelaySec := flag.Int("debounce-delay", 2, "Debounce delay for incoming webhook events, in seconds")
|
||||
debounceDelaySec := flag.Int("debounce-delay", 2, "Debounce delay for incoming webhook events, in seconds") //nolint:mnd
|
||||
flag.Parse()
|
||||
|
||||
if err := common.RequireGiteaSecretToken(); err != nil {
|
||||
@@ -808,7 +808,7 @@ func main() {
|
||||
go consistencyCheckProcess()
|
||||
common.LogInfo("defs:", *defs)
|
||||
|
||||
debounceDelay := 2 * time.Second
|
||||
debounceDelay := 2 * time.Second //nolint:mnd
|
||||
if d := os.Getenv("AUTOGITS_DEBOUNCE_DELAY"); len(d) > 0 {
|
||||
if val, err := time.ParseDuration(d); err == nil {
|
||||
debounceDelay = val
|
||||
|
||||
@@ -64,7 +64,7 @@ func (i *IssueProcessor) pkgPath(packageName string) string {
|
||||
|
||||
func (i *IssueProcessor) Cleanup(git common.Git) {
|
||||
if i.workspacePath != "" {
|
||||
os.RemoveAll(path.Join(git.GetPath(), i.workspacePath))
|
||||
_ = os.RemoveAll(path.Join(git.GetPath(), i.workspacePath))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func (i *IssueProcessor) tryAcceptReparent(config *common.AutogitConfig, srcOrg,
|
||||
|
||||
common.LogInfoCtx(i.ctx, " - Repository", config.Organization+"/"+packageName, "does not exist. Attempting reparent.")
|
||||
if !common.IsDryRun && issue.State == common.GiteaPRState_Open {
|
||||
gitea.SetLabels(org, repo, issue.Index, []string{config.Label(common.Label_NewRepository)})
|
||||
_, _ = gitea.SetLabels(org, repo, issue.Index, []string{config.Label(common.Label_NewRepository)})
|
||||
}
|
||||
|
||||
common.LogDebugCtx(i.ctx, " - Attempting to accept reparent of", srcOrg+"/"+packageName)
|
||||
@@ -254,7 +254,7 @@ func (i *IssueProcessor) handleExistingPRs(config *common.AutogitConfig, package
|
||||
// syncPRMetadata updates PR body and maintainer-edit flag if they have drifted.
|
||||
func (i *IssueProcessor) syncPRMetadata(pr *models.PullRequest, body string) {
|
||||
if pr.Body != body || !pr.AllowMaintainerEdit {
|
||||
Gitea.WithContext(i.ctx).UpdatePullRequest(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Index, &models.EditPullRequestOption{
|
||||
_, _ = Gitea.WithContext(i.ctx).UpdatePullRequest(pr.Base.Repo.Owner.UserName, pr.Base.Repo.Name, pr.Index, &models.EditPullRequestOption{
|
||||
AllowMaintainerEdit: true,
|
||||
Body: body,
|
||||
})
|
||||
@@ -428,7 +428,7 @@ func (i *IssueProcessor) validateRequest(config *common.AutogitConfig, newIssues
|
||||
msg := fmt.Sprintf("Target branch `%s` already exists in `%s/%s`. Skipping and closing issue.", baseBranch, config.Organization, nr.Repository)
|
||||
common.LogErrorCtx(i.ctx, msg)
|
||||
if !common.IsDryRun && issue.State == common.GiteaPRState_Open {
|
||||
gitea.AddIssueComment(org, repo, issue.Index, msg)
|
||||
_ = gitea.AddIssueComment(org, repo, issue.Index, msg)
|
||||
}
|
||||
shouldClose = true
|
||||
continue
|
||||
@@ -511,7 +511,7 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
|
||||
if approved, missing := i.hasRequiredApprovals(config); !approved {
|
||||
common.LogInfoCtx(i.ctx, "Issue is waiting for approvals from:", strings.Join(missing, ", "))
|
||||
if !common.IsDryRun && issue.State == common.GiteaPRState_Open {
|
||||
gitea.SetLabels(org, repo, issue.Index, []string{config.Label(common.Label_ApprovalRequired)})
|
||||
_, _ = gitea.SetLabels(org, repo, issue.Index, []string{config.Label(common.Label_ApprovalRequired)})
|
||||
const approvalMarker = "<!-- autogits: approval-required -->"
|
||||
mentions := make([]string, len(missing))
|
||||
for idx, u := range missing {
|
||||
@@ -540,7 +540,7 @@ func (i *IssueProcessor) ProcessAddIssue(config *common.AutogitConfig) error {
|
||||
return nil
|
||||
} else if len(config.PackageApprovers) > 0 {
|
||||
if !common.IsDryRun && issue.State == common.GiteaPRState_Open {
|
||||
gitea.RemoveLabel(org, repo, issue.Index, config.Label(common.Label_ApprovalRequired))
|
||||
_ = gitea.RemoveLabel(org, repo, issue.Index, config.Label(common.Label_ApprovalRequired))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,7 +649,7 @@ func (i *IssueProcessor) ProcessIssue(configs common.AutogitConfigs) error {
|
||||
}
|
||||
}
|
||||
if config == nil {
|
||||
return fmt.Errorf("Cannot find config for %s", common.TaskRefBranch(org, repo, TargetBranch))
|
||||
return fmt.Errorf("cannot find config for %s", common.TaskRefBranch(org, repo, TargetBranch))
|
||||
}
|
||||
|
||||
prjGitOrg, prjGitRepo, _ := config.GetPrjGit()
|
||||
|
||||
+3
-3
@@ -168,12 +168,12 @@ func main() {
|
||||
}
|
||||
|
||||
checker := CreateDefaultStateChecker(*checkOnStart, req, Gitea, time.Duration(*checkIntervalHours)*time.Hour)
|
||||
go checker.ConsistencyCheckProcess(context.TODO())
|
||||
go checker.ConsistencyCheckProcess(context.TODO()) //nolint:errcheck
|
||||
|
||||
debounceDelay, err := time.ParseDuration(*debounceDelayStr)
|
||||
if err != nil {
|
||||
common.LogError("Invalid debounce delay format:", err, "using default 15s")
|
||||
debounceDelay = 15 * time.Second
|
||||
debounceDelay = 15 * time.Second //nolint:mnd
|
||||
}
|
||||
debouncer := common.NewDebouncer(req, debounceDelay)
|
||||
|
||||
@@ -204,7 +204,7 @@ func updateConfiguration(configFilename string, req *RequestProcessor, orgs *[]s
|
||||
config, err := common.ReadConfigFile(configFilename)
|
||||
if err != nil {
|
||||
common.LogError("Cannot read config files:", err)
|
||||
os.Exit(4)
|
||||
os.Exit(4) //nolint:mnd
|
||||
}
|
||||
|
||||
workflowConfigs, err = common.ResolveWorkflowConfigs(Gitea, config)
|
||||
|
||||
+12
-12
@@ -96,7 +96,7 @@ func fetchGitIfNecessary(ctx context.Context, git common.Git, repoPath, sha stri
|
||||
return nil
|
||||
}
|
||||
common.LogInfoCtx(ctx, "Retrying fetch for", sha, "in", repoPath, "attempt", i+1)
|
||||
time.Sleep(2 * time.Second)
|
||||
time.Sleep(2 * time.Second) //nolint:mnd
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -272,7 +272,7 @@ func AllocatePRProcessor(ctx context.Context, req *models.PullRequest, configs c
|
||||
|
||||
if _, err = os.Stat(filepath.Join(newGit.GetPath(), newWorkspacePath, ".git")); errors.Is(err, os.ErrNotExist) {
|
||||
if _, err = os.Stat(filepath.Join(git.GetPath(), workspacePath, ".git")); err == nil {
|
||||
if err = os.MkdirAll(filepath.Dir(filepath.Join(newGit.GetPath(), newWorkspacePath)), 0777); err != nil {
|
||||
if err = os.MkdirAll(filepath.Dir(filepath.Join(newGit.GetPath(), newWorkspacePath)), 0777); err != nil { //nolint:mnd
|
||||
git.Close() //nolint:errcheck
|
||||
newGit.Close() //nolint:errcheck
|
||||
return nil, err
|
||||
@@ -565,7 +565,7 @@ func (prp *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) error {
|
||||
if errRm := git.GitExec(prjPath, "rm", "-f", submoduleName); errRm != nil {
|
||||
common.LogDebugCtx(prp.ctx, "Failed to remove submodule", submoduleName, ":", errRm)
|
||||
}
|
||||
os.RemoveAll(path.Join(git.GetPath(), prjPath, submoduleName))
|
||||
_ = os.RemoveAll(path.Join(git.GetPath(), prjPath, submoduleName))
|
||||
commitMsg := fmt.Sprintf("auto-created: remove package %s referencing closed PR %d", submoduleName, idx)
|
||||
if errCommit := git.GitExec(prjPath, "commit", "-a", "-m", commitMsg); errCommit != nil {
|
||||
common.LogDebugCtx(prp.ctx, "Failed to commit submodule removal:", errCommit)
|
||||
@@ -692,9 +692,9 @@ func (prp *PRProcessor) CreatePRjGitPR(prjGitPRbranch string, prset *common.PRSe
|
||||
repo := PrjGit.Name
|
||||
idx := pr.Index
|
||||
if isNew {
|
||||
Gitea.WithContext(prp.ctx).SetLabels(org, repo, idx, []string{prset.Config.Label(common.Label_StagingAuto)})
|
||||
_, _ = Gitea.WithContext(prp.ctx).SetLabels(org, repo, idx, []string{prset.Config.Label(common.Label_StagingAuto)})
|
||||
}
|
||||
Gitea.WithContext(prp.ctx).UpdatePullRequest(org, repo, idx, &models.EditPullRequestOption{
|
||||
_, _ = Gitea.WithContext(prp.ctx).UpdatePullRequest(org, repo, idx, &models.EditPullRequestOption{
|
||||
RemoveDeadline: true,
|
||||
})
|
||||
|
||||
@@ -810,7 +810,7 @@ func (prp *PRProcessor) UpdatePrjGitPR(prset *common.PRSet, rebase bool) error {
|
||||
}
|
||||
common.PanicOnError(git.GitExec(prjPath, params...))
|
||||
PrjGitPR.PR.Head.Sha = newHeadCommit
|
||||
Gitea.WithContext(prp.ctx).SetLabels(PrjGit.Owner.UserName, PrjGit.Name, PrjGitPR.PR.Index, []string{prset.Config.Label("PR/updated")})
|
||||
_, _ = Gitea.WithContext(prp.ctx).SetLabels(PrjGit.Owner.UserName, PrjGit.Name, PrjGitPR.PR.Index, []string{prset.Config.Label("PR/updated")})
|
||||
}
|
||||
|
||||
// update PR
|
||||
@@ -828,7 +828,7 @@ func (prp *PRProcessor) UpdatePrjGitPR(prset *common.PRSet, rebase bool) error {
|
||||
return CurrentTitle == NewTitle
|
||||
}
|
||||
if slices.Contains(BotUsers, PrjGitPR.PR.User.UserName) && (PrjGitPR.PR.Body != PrjGitBody || !isPrTitleSame(PrjGitPR.PR.Title, PrjGitTitle)) {
|
||||
Gitea.WithContext(prp.ctx).UpdatePullRequest(PrjGit.Owner.UserName, PrjGit.Name, PrjGitPR.PR.Index, &models.EditPullRequestOption{
|
||||
_, _ = Gitea.WithContext(prp.ctx).UpdatePullRequest(PrjGit.Owner.UserName, PrjGit.Name, PrjGitPR.PR.Index, &models.EditPullRequestOption{
|
||||
RemoveDeadline: true,
|
||||
Title: PrjGitTitle,
|
||||
Body: PrjGitBody,
|
||||
@@ -846,7 +846,7 @@ func (prp *PRProcessor) Process(ctx context.Context, req *models.PullRequest) (e
|
||||
if r := recover(); r != nil {
|
||||
common.LogInfoCtx(prp.ctx, "panic cought in PRProcessor --- recovered")
|
||||
common.LogErrorCtx(prp.ctx, string(debug.Stack()))
|
||||
err = fmt.Errorf("Panic crash: %v", r)
|
||||
err = fmt.Errorf("panic crash: %v", r)
|
||||
}
|
||||
}()
|
||||
config := prp.config
|
||||
@@ -897,7 +897,7 @@ func (prp *PRProcessor) Process(ctx context.Context, req *models.PullRequest) (e
|
||||
common.LogDebugCtx(prp.ctx, "Found PrjGit PR:", common.PRtoString(prjGitPR.PR))
|
||||
if prjGitPR.PR == nil || prjGitPR.PR.Head == nil || prjGitPR.PR.Head.Repo == nil {
|
||||
common.LogInfoCtx(prp.ctx, "PrjGit PR branch has been removed. Cannot process.")
|
||||
return fmt.Errorf("PrjGit PR branch is removed. Cannot process.")
|
||||
return fmt.Errorf("prjgit PR branch is removed, cannot process")
|
||||
}
|
||||
prjGitPRbranch = prjGitPR.PR.Head.Ref
|
||||
|
||||
@@ -931,7 +931,7 @@ func (prp *PRProcessor) Process(ctx context.Context, req *models.PullRequest) (e
|
||||
}
|
||||
}
|
||||
|
||||
PrjGitSubmoduleCheck(prp.ctx, config, git, prjPath, pkgs)
|
||||
_, _ = PrjGitSubmoduleCheck(prp.ctx, config, git, prjPath, pkgs)
|
||||
}
|
||||
|
||||
// manually merge or close entire prset that is still open
|
||||
@@ -1071,7 +1071,7 @@ func (prp *PRProcessor) Process(ctx context.Context, req *models.PullRequest) (e
|
||||
if len(diff) == 0 {
|
||||
common.LogInfoCtx(prp.ctx, "PR is no-op and can be closed. Closing.")
|
||||
if !common.IsDryRun {
|
||||
Gitea.WithContext(prp.ctx).AddComment(prjGitPR.PR, "Pull request no longer contains any changes. Closing.")
|
||||
_ = Gitea.WithContext(prp.ctx).AddComment(prjGitPR.PR, "Pull request no longer contains any changes. Closing.")
|
||||
_, err = Gitea.WithContext(prp.ctx).UpdatePullRequest(prjGitPR.PR.Base.Repo.Owner.UserName, prjGitPR.PR.Base.Repo.Name, prjGitPR.PR.Index, &models.EditPullRequestOption{
|
||||
State: common.GiteaPRState_Closed,
|
||||
})
|
||||
@@ -1194,7 +1194,7 @@ func (w *RequestProcessor) ProcessFunc(ctx context.Context, request *common.Requ
|
||||
if r := recover(); r != nil {
|
||||
common.LogErrorCtx(ctx, "panic caught in RequestProcessor --- recovered")
|
||||
common.LogErrorCtx(ctx, string(debug.Stack()))
|
||||
err = fmt.Errorf("Panic crash: %v", r)
|
||||
err = fmt.Errorf("panic crash: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func (s *DefaultStateChecker) ProcessPR(ctx context.Context, pr *models.PullRequ
|
||||
if r := recover(); r != nil {
|
||||
common.LogErrorCtx(ctx, "panic caught in ProcessPR", common.PRtoString(pr))
|
||||
common.LogErrorCtx(ctx, string(debug.Stack()))
|
||||
err = fmt.Errorf("Panic crash: %v", r)
|
||||
err = fmt.Errorf("panic crash: %v", r)
|
||||
}
|
||||
}()
|
||||
return ProcesPullRequest(ctx, pr, common.AutogitConfigs{config}, nil)
|
||||
@@ -69,7 +69,7 @@ nextSubmodule:
|
||||
})
|
||||
|
||||
// check if the committed changes are syned with branches
|
||||
commits, err := gitea.GetRecentCommits(config.Organization, submoduleName, branch, 10)
|
||||
commits, err := gitea.GetRecentCommits(config.Organization, submoduleName, branch, 10) //nolint:mnd
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error fetching recent commits for %s/%s. Err: %w", config.Organization, submoduleName, err)
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (s *DefaultStateChecker) VerifyProjectState(ctx context.Context, config *co
|
||||
common.LogErrorCtx(ctx, err)
|
||||
}
|
||||
common.LogErrorCtx(ctx, string(debug.Stack()))
|
||||
err = fmt.Errorf("Panic crash: %v", r)
|
||||
err = fmt.Errorf("panic crash: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -133,7 +133,7 @@ func (s *DefaultStateChecker) VerifyProjectState(ctx context.Context, config *co
|
||||
|
||||
PrjGitRepo, err := Gitea.WithContext(ctx).CreatePrjGitRepoIfNotExist(git.WithContext(ctx), config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error fetching or creating '%s' -- aborting verifyProjectState(). Err: %w", common.TaskRefBranch(prjGitOrg, prjGitRepo, prjGitBranch), err)
|
||||
return nil, fmt.Errorf("error fetching or creating '%s', aborting verifyProjectState(): %w", common.TaskRefBranch(prjGitOrg, prjGitRepo, prjGitBranch), err)
|
||||
}
|
||||
|
||||
_, err = git.GitClone(prjPath, prjGitBranch, PrjGitRepo.SSHURL)
|
||||
@@ -190,7 +190,7 @@ func (s *DefaultStateChecker) CheckRepos(ctx context.Context) {
|
||||
}
|
||||
|
||||
for _, pr := range prs {
|
||||
s.ProcessPR(ctx, pr, config)
|
||||
_ = s.ProcessPR(ctx, pr, config)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user