Skip to content

Commit 6d0b1df

Browse files
authored
Rename generic utility files in pkg/cli to reflect their specific purpose (#3627)
1 parent f8f280e commit 6d0b1df

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ import (
1010
"github.com/githubnext/gh-aw/pkg/workflow"
1111
)
1212

13-
var frontmatterUtilsLog = logger.New("cli:frontmatter_utils")
13+
var frontmatterEditorLog = logger.New("cli:frontmatter_editor")
1414

1515
// UpdateFieldInFrontmatter updates a field in the frontmatter while preserving the original formatting
1616
// when possible. It tries to preserve whitespace, comments, and formatting by working with the raw
1717
// frontmatter lines, similar to how addSourceToWorkflow works.
1818
func UpdateFieldInFrontmatter(content, fieldName, fieldValue string) (string, error) {
19-
frontmatterUtilsLog.Printf("Updating frontmatter field: %s = %s", fieldName, fieldValue)
19+
frontmatterEditorLog.Printf("Updating frontmatter field: %s = %s", fieldName, fieldValue)
2020

2121
// Parse frontmatter using parser package
2222
result, err := parser.ExtractFrontmatterFromContent(content)
2323
if err != nil {
24-
frontmatterUtilsLog.Printf("Failed to parse frontmatter: %v", err)
24+
frontmatterEditorLog.Printf("Failed to parse frontmatter: %v", err)
2525
return "", fmt.Errorf("failed to parse frontmatter: %w", err)
2626
}
2727

2828
// Try to preserve original frontmatter formatting by manually updating the field
2929
if len(result.FrontmatterLines) > 0 {
30-
frontmatterUtilsLog.Printf("Using raw frontmatter lines for field update (%d lines)", len(result.FrontmatterLines))
30+
frontmatterEditorLog.Printf("Using raw frontmatter lines for field update (%d lines)", len(result.FrontmatterLines))
3131
// Look for existing field in the raw lines
3232
fieldUpdated := false
3333
frontmatterLines := make([]string, len(result.FrontmatterLines))
@@ -55,7 +55,7 @@ func UpdateFieldInFrontmatter(content, fieldName, fieldValue string) (string, er
5555
frontmatterLines[i] = fmt.Sprintf("%s%s: %s", leadingSpace, fieldName, fieldValue)
5656
}
5757
fieldUpdated = true
58-
frontmatterUtilsLog.Printf("Updated existing field %s in place (line %d)", fieldName, i+1)
58+
frontmatterEditorLog.Printf("Updated existing field %s in place (line %d)", fieldName, i+1)
5959
break
6060
}
6161
}
@@ -64,7 +64,7 @@ func UpdateFieldInFrontmatter(content, fieldName, fieldValue string) (string, er
6464
if !fieldUpdated {
6565
newField := fmt.Sprintf("%s: %s", fieldName, fieldValue)
6666
frontmatterLines = append(frontmatterLines, newField)
67-
frontmatterUtilsLog.Printf("Added new field %s at end of frontmatter", fieldName)
67+
frontmatterEditorLog.Printf("Added new field %s at end of frontmatter", fieldName)
6868
}
6969

7070
// Reconstruct the file with preserved formatting
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/githubnext/gh-aw/pkg/logger"
1313
)
1414

15-
var sharedUtilsLog = logger.New("cli:shared_utils")
15+
var prAutomergeLog = logger.New("cli:pr_automerge")
1616

1717
// PullRequest represents a GitHub Pull Request
1818
type PullRequest struct {
@@ -27,7 +27,7 @@ type PullRequest struct {
2727
// AutoMergePullRequestsCreatedAfter checks for open PRs in the repository created after a specific time and auto-merges them
2828
// This function filters PRs to only those created after the specified time to avoid merging unrelated PRs
2929
func AutoMergePullRequestsCreatedAfter(repoSlug string, createdAfter time.Time, verbose bool) error {
30-
sharedUtilsLog.Printf("Checking for PRs in repo=%s created after %s", repoSlug, createdAfter.Format(time.RFC3339))
30+
prAutomergeLog.Printf("Checking for PRs in repo=%s created after %s", repoSlug, createdAfter.Format(time.RFC3339))
3131

3232
if verbose {
3333
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Checking for open pull requests in %s created after %s", repoSlug, createdAfter.Format(time.RFC3339))))
@@ -37,7 +37,7 @@ func AutoMergePullRequestsCreatedAfter(repoSlug string, createdAfter time.Time,
3737
listCmd := exec.Command("gh", "pr", "list", "--repo", repoSlug, "--json", "number,title,isDraft,mergeable,createdAt,updatedAt")
3838
output, err := listCmd.Output()
3939
if err != nil {
40-
sharedUtilsLog.Printf("Failed to list pull requests: %v", err)
40+
prAutomergeLog.Printf("Failed to list pull requests: %v", err)
4141
return fmt.Errorf("failed to list pull requests: %w", err)
4242
}
4343

@@ -64,14 +64,14 @@ func AutoMergePullRequestsCreatedAfter(repoSlug string, createdAfter time.Time,
6464
}
6565

6666
if len(eligiblePRs) == 0 {
67-
sharedUtilsLog.Print("No eligible PRs found for auto-merge")
67+
prAutomergeLog.Print("No eligible PRs found for auto-merge")
6868
if verbose {
6969
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("No pull requests found created after %s", createdAfter.Format(time.RFC3339))))
7070
}
7171
return nil
7272
}
7373

74-
sharedUtilsLog.Printf("Found %d eligible PRs for auto-merge", len(eligiblePRs))
74+
prAutomergeLog.Printf("Found %d eligible PRs for auto-merge", len(eligiblePRs))
7575
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Found %d pull request(s) created after workflow start time", len(eligiblePRs))))
7676

7777
for _, pr := range eligiblePRs {
@@ -118,7 +118,7 @@ func AutoMergePullRequestsLegacy(repoSlug string, verbose bool) error {
118118

119119
// WaitForWorkflowCompletion waits for a workflow run to complete, with a specified timeout
120120
func WaitForWorkflowCompletion(repoSlug, runID string, timeoutMinutes int, verbose bool) error {
121-
sharedUtilsLog.Printf("Waiting for workflow completion: repo=%s, runID=%s, timeout=%d minutes", repoSlug, runID, timeoutMinutes)
121+
prAutomergeLog.Printf("Waiting for workflow completion: repo=%s, runID=%s, timeout=%d minutes", repoSlug, runID, timeoutMinutes)
122122

123123
if verbose {
124124
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Waiting for workflow completion (timeout: %d minutes)", timeoutMinutes)))

0 commit comments

Comments
 (0)