Skip to content

feat(prinfo): expand author field to include account type#2934

Merged
javirln merged 5 commits intochainloop-dev:mainfrom
javirln:javirln/pr-info-author-type
Mar 24, 2026
Merged

feat(prinfo): expand author field to include account type#2934
javirln merged 5 commits intochainloop-dev:mainfrom
javirln:javirln/pr-info-author-type

Conversation

@javirln
Copy link
Member

@javirln javirln commented Mar 24, 2026

Summary

  • Expand author field in PR info from a plain string to an object with login and type (User/Bot/unknown), enabling policies to distinguish bot-authored PRs without relying on naming conventions
  • Add JSON schema v1.3 with oneOf supporting both string (backwards compat) and object formats
  • Custom UnmarshalJSON on Data handles both formats at the Go struct level, converting legacy string authors to Author{Login: str, Type: "unknown"}
  • GitHub: extracts author type from the PR event payload (user.type field)
  • GitLab: refactors fetchGitLabReviewers into fetchGitLabMRDetails to extract author bot status from the MR API (author.bot field) in a single call, with fallback to env var if API unavailable
  • GitLab reviewers also get bot detection from the same API response

Add PR info schema v1.3 where author accepts both a string (backwards
compatible) and an object with login and type fields (User/Bot/unknown).

GitHub populates the type from the event payload's user.type field.
GitLab sets type to "unknown" since CI env vars don't expose it.

This enables policies to check author type directly instead of relying
on naming conventions like the [bot] suffix.

Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
@javirln javirln self-assigned this Mar 24, 2026
@javirln javirln requested review from Piskoo, jiparis and migmartri March 24, 2026 12:12
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/prinfo/prinfo.go">

<violation number="1" location="internal/prinfo/prinfo.go:49">
P1: This change breaks runtime backward compatibility for old PR info payloads with string `author`: decoding fails before schema validation can apply the v1.3 `oneOf` rule.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Add Data.UnmarshalJSON to handle both string (v1.0-v1.2) and object
(v1.3) author formats at the Go struct level. String authors are
converted to Author{Login: str, Type: "unknown"}.

Also fixes gofmt formatting issues in prmetadata.go and test files.

Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/prinfo/prinfo.go">

<violation number="1" location="internal/prinfo/prinfo.go:80">
P2: Unmarshaling JSON `null` into a struct value leaves it as an empty struct rather than `nil`. Unmarshal into a pointer instead to properly handle nulls.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@javirln javirln marked this pull request as draft March 24, 2026 12:36
javirln added 2 commits March 24, 2026 13:38
Refactor fetchGitLabReviewers into fetchGitLabMRDetails to extract both
author and reviewer information from the MR API response in a single
call. Uses the GitLab `bot` boolean field to set author/reviewer type
to "User" or "Bot". Falls back to GITLAB_USER_LOGIN with type "unknown"
if the API call fails (best-effort).

Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Address review feedback: explicitly check for JSON null in the author
field to prevent unmarshaling null into an empty struct.

Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
@javirln javirln marked this pull request as ready for review March 24, 2026 12:42
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

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>
@javirln javirln merged commit 8692875 into chainloop-dev:main Mar 24, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants