gitea-pr: token-file auth + skip duplicate PR creation #2

Merged
branderson merged 2 commits from worktree-gitea-pr-review-workflow into master 2026-07-12 22:15:02 -07:00
Owner

Follow-up to #1 (merged), continuing on the same branch, addressing review
feedback and a follow-up request:

  1. Read GITEA_TOKEN from a dedicated file (~/.config/gitea/token,
    chmod 600) instead of a global exported shell variable, so the token
    isn't visible to every process in every shell — only to gitea-pr itself.
    GITEA_TOKEN env var still works as a one-off override. Migrated the
    existing token out of ~/.profile.local into the new file as part of
    this change.

  2. gitea-pr create now checks for an existing open PR on the current
    branch before creating a new one (GET .../pulls?state=open, matched on
    head.ref), returning the existing PR's URL instead of creating a
    duplicate. Note: this only matches open PRs by design — once a PR is
    merged, new commits on the same branch correctly get a new PR, which is
    exactly how PR #2 itself came to exist.

Testing: shellcheck clean (-e SC2029 -e SC2155) on both commits. Live-
tested against the real server: confirmed the missing-token error message,
confirmed comments/reviews still fetch correctly via the new token-file path,
and confirmed the existing-PR check both short-circuits correctly (verified
against this same open PR after creation) and still creates a fresh PR when
none is open.

Follow-up to #1 (merged), continuing on the same branch, addressing review feedback and a follow-up request: 1. **Read GITEA_TOKEN from a dedicated file** (`~/.config/gitea/token`, chmod 600) instead of a global exported shell variable, so the token isn't visible to every process in every shell — only to gitea-pr itself. `GITEA_TOKEN` env var still works as a one-off override. Migrated the existing token out of `~/.profile.local` into the new file as part of this change. 2. **`gitea-pr create` now checks for an existing open PR** on the current branch before creating a new one (GET .../pulls?state=open, matched on `head.ref`), returning the existing PR's URL instead of creating a duplicate. Note: this only matches *open* PRs by design — once a PR is merged, new commits on the same branch correctly get a new PR, which is exactly how PR #2 itself came to exist. **Testing:** shellcheck clean (`-e SC2029 -e SC2155`) on both commits. Live- tested against the real server: confirmed the missing-token error message, confirmed comments/reviews still fetch correctly via the new token-file path, and confirmed the existing-PR check both short-circuits correctly (verified against this same open PR after creation) and still creates a fresh PR when none is open.
branderson changed title from should not matter to gitea-pr: token-file auth + skip duplicate PR creation 2026-07-12 22:03:28 -07:00
branderson added 2 commits 2026-07-12 22:14:15 -07:00
gitea-pr create now checks for an existing open PR on the current
branch first and returns its URL instead of creating a new one. Only
matches open PRs by design -- once merged, new commits on the same
branch correctly get a new PR.
The lookup was matching on head.ref alone, so running create with a
different --base for the same branch would silently return an
unrelated PR's URL instead of opening a new one. Resolve base before
the check and filter on both head.ref and base.ref.
branderson force-pushed worktree-gitea-pr-review-workflow from 7436311022 to 06e60bda8c 2026-07-12 22:14:15 -07:00 Compare
branderson merged commit ddd7f6bf2c into master 2026-07-12 22:15:02 -07:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: branderson/dotfiles#2