Skip to content

Commit d7fa83e

Browse files
committed
fix: extract User/Bot/unknown author type strings as constants
Address goconst lint: extract repeated "User", "Bot", "unknown" strings into AuthorTypeUser, AuthorTypeBot, AuthorTypeUnknown constants in the prinfo package. Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
1 parent 636e1c2 commit d7fa83e

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

internal/prinfo/prinfo.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const (
2525
EvidenceID = "CHAINLOOP_PR_INFO"
2626
// EvidenceSchemaURL is the URL to the JSON schema for PR/MR info
2727
EvidenceSchemaURL = "https://schemas.chainloop.dev/prinfo/1.3/pr-info.schema.json"
28+
29+
// AuthorTypeUser represents a human user account
30+
AuthorTypeUser = "User"
31+
// AuthorTypeBot represents a bot/service account
32+
AuthorTypeBot = "Bot"
33+
// AuthorTypeUnknown represents an account with unknown type
34+
AuthorTypeUnknown = "unknown"
2835
)
2936

3037
// Author represents the author of the PR/MR with account type information
@@ -86,7 +93,7 @@ func (d *Data) UnmarshalJSON(b []byte) error {
8693
// Fall back to string format
8794
var login string
8895
if err := json.Unmarshal(aux.Author, &login); err == nil {
89-
d.Author = &Author{Login: login, Type: "unknown"}
96+
d.Author = &Author{Login: login, Type: AuthorTypeUnknown}
9097
return nil
9198
}
9299

pkg/attestation/crafter/prmetadata.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ func fetchGitLabMRDetails(ctx context.Context, baseURL, projectPath, mrIID, toke
439439

440440
// Extract author with bot detection
441441
if mrResponse.Author.Username != "" {
442-
authorType := "User"
442+
authorType := prinfo.AuthorTypeUser
443443
if mrResponse.Author.Bot {
444-
authorType = "Bot"
444+
authorType = prinfo.AuthorTypeBot
445445
}
446446
details.Author = &prinfo.Author{
447447
Login: mrResponse.Author.Username,
@@ -451,9 +451,9 @@ func fetchGitLabMRDetails(ctx context.Context, baseURL, projectPath, mrIID, toke
451451

452452
// Extract reviewers with bot detection
453453
for _, r := range mrResponse.Reviewers {
454-
reviewerType := "User"
454+
reviewerType := prinfo.AuthorTypeUser
455455
if r.Bot {
456-
reviewerType = "Bot"
456+
reviewerType = prinfo.AuthorTypeBot
457457
}
458458
details.Reviewers = append(details.Reviewers, prinfo.Reviewer{
459459
Login: r.Username,
@@ -469,9 +469,9 @@ func fetchGitLabMRDetails(ctx context.Context, baseURL, projectPath, mrIID, toke
469469
// to one of the allowed values: "User", "Bot", or "unknown".
470470
func normalizeAuthorType(authorType string) string {
471471
switch authorType {
472-
case "User", "Bot":
472+
case prinfo.AuthorTypeUser, prinfo.AuthorTypeBot:
473473
return authorType
474474
default:
475-
return "unknown"
475+
return prinfo.AuthorTypeUnknown
476476
}
477477
}

0 commit comments

Comments
 (0)