Skip to content

Make repository grant and revoke direct-only with direct-collaborators-only - #199

Closed
c1-squire-dev[bot] wants to merge 2 commits into
mainfrom
john.allers/CXP-909/direct-collaborator-grant-revoke
Closed

c1-squire-dev[bot] wants to merge 2 commits into
mainfrom
john.allers/CXP-909/direct-collaborator-grant-revoke

Conversation

@c1-squire-dev

@c1-squire-dev c1-squire-dev Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

With direct-collaborators-only on, Grant returned GrantAlreadyExists for a user who had access only through a team or org base permission. The effective-access check short-circuited before AddCollaborator. The sync lists only direct collaborators in this mode, so the grant never appeared. This regressed in #174.

With the flag on, Grant now always calls AddCollaborator and drops the GrantReplaced lookup. Revoke removes only the direct collaborator, treats a 404 as already revoked, and logs a warning if team or org access remains. Behavior with the flag off is unchanged. The option description and docs now explain this. config_schema.json was regenerated from the built binary.

Testing

  • go build ./...: pass
  • go vet ./...: pass
  • go test ./...: pass (new tests cover grant with the flag on and off, revoke of a non-direct user, and revoke with team access remaining)
  • golangci-lint run: 0 issues

🤖 Generated with Claude Code

…s-only

With the flag on, Grant returned GrantAlreadyExists for users who had access
only through a team or org base permission. Effective-access checks hid the
missing direct record, and the sync lists only direct collaborators, so the
grant never appeared.

With the flag on, Grant now always calls AddCollaborator. Revoke removes only
the direct collaborator, treats a 404 as already revoked, and logs a warning
when team or org access remains. Behavior with the flag off is unchanged.

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@c1-squire-dev
c1-squire-dev Bot requested a review from a team November 23, 2026 19:32
@linear-code

linear-code Bot commented Nov 23, 2026

Copy link
Copy Markdown

CXP-909

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 46d5685b1293

Connector PR Review: Make repository grant and revoke direct-only with direct-collaborators-only

Blocking Issues: 0 | Suggestions: 3 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 6716532fafb2.
Review mode: full
View review run

Review Summary

The existing effective-access lookup (IsCollaborator + GetPermissionLevel) moves into existingUserGrant. When directCollaboratorsOnly is set, Grant skips that lookup and always calls AddCollaborator, without a GrantAlreadyExists/GrantReplaced short-circuit. With the flag on, Revoke also treats a 404 from RemoveCollaborator as success and logs a one-shot Warn if IsCollaborator still reports access. Behavior with the flag off is unchanged. The mock gains repository-role and permission-level handlers to support the new tests.

I scanned the full PR diff for security and correctness, and read the full Grant/Revoke flow per PR1. I applied the trusted repo-local criteria:

  • Entity sources (P1/P2/PR2): correct. The principal comes from principal.Id, the repo from en.Resource.Id, and nothing uses ParentResourceId.
  • Log levels (A): the new Warn is per-revoke and actionable, so no sampling is needed.
  • Error wrapping (E): unchanged.
  • 404 handling (S6/P3): applied by analogy to Revoke's new 404 handling; finding below.
  • Docs (BP3/D1): applied; finding below.

No go.mod/go.sum changes. No coverage gaps.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • New (medium confidence) pkg/connector/repository.go:575: Revoke treats any 404 from RemoveCollaborator as already revoked when the flag is on. GitHub documents 204/403/422 for this endpoint and uses 404 to hide permission failures, so a failed revoke could be reported as success. The new "non-direct user" test depends on a mock-only 404.
  • New pkg/connector/repository.go:432: With the flag on, GrantReplaced is also dropped for existing direct collaborators. Granting pull to a direct admin downgrades them via AddCollaborator, but C1 keeps the stale higher grants until the next sync. A direct-affiliation lookup would keep the signal without the team-access short-circuit.
  • New docs/connector.mdx:494-504: The "Optimize sync for large organizations" section was not updated. It still says access data "is equivalent" and does not describe the new direct-only grant/revoke semantics (only docs-info.md and the config description changed).
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/connector/repository.go`:
- Around line 574-578: Revoke treats any 404 from Repositories.RemoveCollaborator as "already revoked" when directCollaboratorsOnly is on. GitHub's DELETE collaborator endpoint documents 204/403/422, and GitHub uses 404 to hide permission failures, so this can turn a failed revoke into a success. Either drop the 404 carve-out (GitHub already returns 204 for non-collaborators), or add a doc comment on the call stating the vendor's 404 semantics and confirm absence (e.g. via a direct-affiliation collaborator check) before returning success. Update the mock in test/mocks/github.go removeRepositoryCollaborator to match the real API.
- Around line 431-441: With directCollaboratorsOnly on, Grant no longer emits GrantReplaced even when the user is already a direct collaborator with a different role, so C1 keeps stale higher-permission grants after AddCollaborator overwrites the role. Consider a direct-only lookup (ListCollaborators with Affiliation "direct", or the direct-collaborator permission) to compute replacedGrantID and GrantAlreadyExists without consulting team/org-derived access.

In `docs/connector.mdx`:
- Around line 494-504: Update the "Optimize sync for large organizations" section to state that with this option on, repository grants always create a direct collaborator record and repository revokes remove only that record, leaving team/org-base access unchanged. Revise the "Repository access data in C1 is equivalent" sentence accordingly.


resp, er := o.client.Repositories.RemoveCollaborator(ctx, repo.GetOwner().GetLogin(), repo.GetName(), user.GetLogin())
if er != nil {
alreadyRevoked := o.directCollaboratorsOnly && resp != nil && resp.StatusCode == http.StatusNotFound

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion (medium confidence): GitHub documents DELETE /repos/{owner}/{repo}/collaborators/{username} as returning 204, 403, or 422. A 404 is not its "not a collaborator" answer; GitHub uses 404 to hide permission failures. Treating any 404 as already revoked can report a revoke as successful when the token could not perform it. The new test only passes because the mock invents a 404 for non-collaborators. Consider removing the 404 carve-out, or documenting the vendor's 404 semantics on this call and checking IsCollaborator/direct membership before reporting success.

var replacedGrantID string
if collaborator {
permLevel, resp, err := o.client.Repositories.GetPermissionLevel(ctx, repo.GetOwner().GetLogin(), repo.GetName(), user.GetLogin())
if !o.directCollaboratorsOnly {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: With the flag on, the GrantReplaced annotation is dropped even for users who are already direct collaborators. Example: a direct admin user is granted pull. AddCollaborator downgrades them, but C1 keeps the stale admin/maintain/push grants until the next sync. The PR description says this is deliberate. Still, a direct-only lookup (e.g. ListCollaborators with Affiliation: "direct" filtered to the login, or the sync's direct-collaborator source) would keep the replaced-grant signal without reintroducing the team-access short-circuit.

Comment thread docs/docs-info.md
`--sync-last-activity` — emit the audit-log usage event feed. Hidden from `--help` and from the GUI config here, because it only applies to GitHub Enterprise audit-log access; `baton-github-enterprise` sets it directly instead of going through this CLI layer
`--omit-archived-repositories` — skip archived repositories
`--direct-collaborators-only` — reduce API calls on large organizations
`--direct-collaborators-only` — reduce API calls on large organizations. With this option on, repository grants create a direct collaborator record, and repository revokes remove only that record. Access through teams is separate and is not changed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: The customer-facing docs/connector.mdx section "Optimize sync for large organizations" (around lines 494-504) was not updated. It still says repository access data "is equivalent" and does not mention that, with this option on, grants always create a direct collaborator and revokes leave team/org access in place. Please add the same note there (D1/BP3).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a direct-only grant and revoke note to the Optimize sync section in docs/connector.mdx in commit 7d9ce4c.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 7d9ce4c80648

Connector PR Review: Make repository grant and revoke direct-only with direct-collaborators-only

Blocking Issues: 0 | Suggestions: 3 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 6716532fafb2.
Review mode: full
View review run

Review Summary

The existing effective-access lookup (IsCollaborator + GetPermissionLevel) moves into existingUserGrant. When directCollaboratorsOnly is set, Grant skips that lookup and always calls AddCollaborator, without a GrantAlreadyExists/GrantReplaced short-circuit. With the flag on, Revoke also treats a 404 from RemoveCollaborator as success and logs a one-shot Warn if IsCollaborator still reports access. Behavior with the flag off is unchanged. The mock gains repository-role and permission-level handlers to support the new tests.

I scanned the full PR diff for security and correctness, and read the full Grant/Revoke flow per PR1. I applied the trusted repo-local criteria:

  • Entity sources (P1/P2/PR2): correct. The principal comes from principal.Id, the repo from en.Resource.Id, and nothing uses ParentResourceId.
  • Log levels (A): the new Warn is per-revoke and actionable, so no sampling is needed.
  • Error wrapping (E): unchanged.
  • 404 handling (S6/P3): applied by analogy to Revoke's new 404 handling; finding below.
  • Docs (BP3/D1): applied; finding below.

No go.mod/go.sum changes. No coverage gaps.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • New (medium confidence) pkg/connector/repository.go:575: Revoke treats any 404 from RemoveCollaborator as already revoked when the flag is on. GitHub documents 204/403/422 for this endpoint and uses 404 to hide permission failures, so a failed revoke could be reported as success. The new "non-direct user" test depends on a mock-only 404.
  • New pkg/connector/repository.go:432: With the flag on, GrantReplaced is also dropped for existing direct collaborators. Granting pull to a direct admin downgrades them via AddCollaborator, but C1 keeps the stale higher grants until the next sync. A direct-affiliation lookup would keep the signal without the team-access short-circuit.
  • New docs/connector.mdx:494-504: The "Optimize sync for large organizations" section was not updated. It still says access data "is equivalent" and does not describe the new direct-only grant/revoke semantics (only docs-info.md and the config description changed).
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/connector/repository.go`:
- Around line 574-578: Revoke treats any 404 from Repositories.RemoveCollaborator as "already revoked" when directCollaboratorsOnly is on. GitHub's DELETE collaborator endpoint documents 204/403/422, and GitHub uses 404 to hide permission failures, so this can turn a failed revoke into a success. Either drop the 404 carve-out (GitHub already returns 204 for non-collaborators), or add a doc comment on the call stating the vendor's 404 semantics and confirm absence (e.g. via a direct-affiliation collaborator check) before returning success. Update the mock in test/mocks/github.go removeRepositoryCollaborator to match the real API.
- Around line 431-441: With directCollaboratorsOnly on, Grant no longer emits GrantReplaced even when the user is already a direct collaborator with a different role, so C1 keeps stale higher-permission grants after AddCollaborator overwrites the role. Consider a direct-only lookup (ListCollaborators with Affiliation "direct", or the direct-collaborator permission) to compute replacedGrantID and GrantAlreadyExists without consulting team/org-derived access.

In `docs/connector.mdx`:
- Around line 494-504: Update the "Optimize sync for large organizations" section to state that with this option on, repository grants always create a direct collaborator record and repository revokes remove only that record, leaving team/org-base access unchanged. Revise the "Repository access data in C1 is equivalent" sentence accordingly.

Reviewed commit: 46d5685b1293

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No blocking issues found — see the full review report

Describe direct-only grant and revoke behavior in the Optimize sync section.

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit 7d9ce4c80648

Connector PR Review: Make repository grant and revoke direct-only with direct-collaborators-only

Blocking Issues: 0 | Suggestions: 2 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 6716532fafb2.
Review mode: incremental since 46d5685
View review run

Review Summary

When direct-collaborators-only is on, this PR changes repository Grant so it always calls AddCollaborator. The effective-access check, which now lives in existingUserGrant, runs only when the flag is off. Revoke removes only the direct collaborator, treats a 404 as already revoked, and logs a warning when team or org access remains. The config description, config_schema.json, the docs and the mocks/tests are updated to match. The new commit (7d9ce4c) only changes docs: it adds a "Direct-only grant and revoke" bullet to the "Optimize sync for large organizations" section of docs/connector.mdx and changes "equivalent" to "equivalent for sync".

I scanned the full PR diff for security and correctness problems. The incremental diff was complete, with no dropped paths and no truncation. I applied the trusted repo-local criteria:

  • Provisioning entity sources (P1/P2/PR2): correct. The principal comes from principal.Id and the repo from en.Resource.Id, with no ParentResourceId use.
  • Log levels (L1/L6): the Revoke warning is one-shot per call.
  • Error wrapping (E1/E2): the existing wrapGitHubError is used.
  • Sync rules (S/R7): not applicable, because no List, Entitlements or Grants path changed.
  • Breaking-change gate (BP1/BP5): the behavior change is behind the existing opt-in flag and is documented.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • Prior — still present (medium confidence) pkg/connector/repository.go:575: with the flag on, Revoke treats any 404 from RemoveCollaborator as already revoked. GitHub documents 204/403/422 for this endpoint and uses 404 to hide permission or visibility failures, so a revoke that failed could be reported as a success. No client-side doc comment says what a 404 from this vendor means here. The "non-direct user" test relies on a 404 that only the mock produces.
  • Prior — still present pkg/connector/repository.go:432: with the flag on, the GrantReplaced lookup is also skipped for users who are already direct collaborators. Granting pull to a direct admin downgrades them through AddCollaborator, but C1 keeps the stale higher grant until the next sync. A lookup that checks only direct affiliation would keep the signal without bringing back the team-access short-circuit.

Resolved prior findings

  • docs/connector.mdx staleness (thread on docs/docs-info.md:76) is fixed. docs/connector.mdx:503 now has the "Direct-only grant and revoke" bullet, and the "equivalent" sentence is now scoped to sync (docs/connector.mdx:505).
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/connector/repository.go`:
- Around line 575: When directCollaboratorsOnly is on, Revoke treats any 404 from RemoveCollaborator as already revoked. GitHub returns 404 for permission/visibility failures, and its documented responses for this endpoint are 204/403/422. Either drop the 404 special case (GitHub returns 204 for a non-collaborator), or confirm the 404 means "not a direct collaborator" before treating it as success, for example by checking direct affiliation with the collaborators list filtered by affiliation=direct. Then document the vendor's 404 semantics in a comment next to the call, and make the mock and test match real GitHub behavior.
- Around line 432: When directCollaboratorsOnly is on, the GrantReplaced annotation is dropped even for existing direct collaborators. Look up only the user's direct collaborator permission (for example ListCollaborators with Affiliation "direct", or check the direct collaborator record) and, if the user is a direct collaborator with a different permission, return GrantReplaced for the old permission's grant ID, without returning GrantAlreadyExists for team or org-derived access.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Connector PR Review: Make repository grant and revoke direct-only with direct-collaborators-only

Blocking Issues: 0 | Suggestions: 2 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 6716532fafb2.
Review mode: incremental since 46d5685
View review run

Review Summary

When direct-collaborators-only is on, this PR changes repository Grant so it always calls AddCollaborator. The effective-access check, which now lives in existingUserGrant, runs only when the flag is off. Revoke removes only the direct collaborator, treats a 404 as already revoked, and logs a warning when team or org access remains. The config description, config_schema.json, the docs and the mocks/tests are updated to match. The new commit (7d9ce4c) only changes docs: it adds a "Direct-only grant and revoke" bullet to the "Optimize sync for large organizations" section of docs/connector.mdx and changes "equivalent" to "equivalent for sync".

I scanned the full PR diff for security and correctness problems. The incremental diff was complete, with no dropped paths and no truncation. I applied the trusted repo-local criteria:

  • Provisioning entity sources (P1/P2/PR2): correct. The principal comes from principal.Id and the repo from en.Resource.Id, with no ParentResourceId use.
  • Log levels (L1/L6): the Revoke warning is one-shot per call.
  • Error wrapping (E1/E2): the existing wrapGitHubError is used.
  • Sync rules (S/R7): not applicable, because no List, Entitlements or Grants path changed.
  • Breaking-change gate (BP1/BP5): the behavior change is behind the existing opt-in flag and is documented.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

  • Prior — still present (medium confidence) pkg/connector/repository.go:575: with the flag on, Revoke treats any 404 from RemoveCollaborator as already revoked. GitHub documents 204/403/422 for this endpoint and uses 404 to hide permission or visibility failures, so a revoke that failed could be reported as a success. No client-side doc comment says what a 404 from this vendor means here. The "non-direct user" test relies on a 404 that only the mock produces.
  • Prior — still present pkg/connector/repository.go:432: with the flag on, the GrantReplaced lookup is also skipped for users who are already direct collaborators. Granting pull to a direct admin downgrades them through AddCollaborator, but C1 keeps the stale higher grant until the next sync. A lookup that checks only direct affiliation would keep the signal without bringing back the team-access short-circuit.

Resolved prior findings

  • docs/connector.mdx staleness (thread on docs/docs-info.md:76) is fixed. docs/connector.mdx:503 now has the "Direct-only grant and revoke" bullet, and the "equivalent" sentence is now scoped to sync (docs/connector.mdx:505).
Prompt for AI agents
Verify each finding against the current code and only fix it if needed.

## Suggestions

In `pkg/connector/repository.go`:
- Around line 575: When directCollaboratorsOnly is on, Revoke treats any 404 from RemoveCollaborator as already revoked. GitHub returns 404 for permission/visibility failures, and its documented responses for this endpoint are 204/403/422. Either drop the 404 special case (GitHub returns 204 for a non-collaborator), or confirm the 404 means "not a direct collaborator" before treating it as success, for example by checking direct affiliation with the collaborators list filtered by affiliation=direct. Then document the vendor's 404 semantics in a comment next to the call, and make the mock and test match real GitHub behavior.
- Around line 432: When directCollaboratorsOnly is on, the GrantReplaced annotation is dropped even for existing direct collaborators. Look up only the user's direct collaborator permission (for example ListCollaborators with Affiliation "direct", or check the direct collaborator record) and, if the user is a direct collaborator with a different permission, return GrantReplaced for the old permission's grant ID, without returning GrantAlreadyExists for team or org-derived access.

Reviewed commit: 7d9ce4c80648

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No blocking issues found — see the full review report

@johnallers johnallers closed this Nov 23, 2026
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.

1 participant