feat: revive gh-attach for GHE React UI with session reuse#13
Merged
Conversation
Solves two long-standing problems. 1. Everyone hits SAML re-auth several times a day when gh-attach drives the browser. session-stop tore down the browser between invocations, and session-only cookies died with it. Add --session NAME + --keep-session so a single persistent playwright-cli session can serve many uploads. One-time login, the rest of the day is free. 2. GitHub Enterprise renders issue/PR pages as a React app. The app does not expose the file-attachment custom element, so Direct mode never worked on GHE. Fix Browser mode to work on GHE. Read the upload URL from textarea.value, not the accessibility snapshot src attribute. Re-fetch the drop-zone ref per image because refs are reissued on every snapshot. Also adds --url-only so callers that manage their own comment posting can use gh-attach purely as an uploader. Example callers: a wrapper that combines several uploads with 'gh pr review --comment'. Other robustness fixes folded in. - playwright-cli sandbox: daemon allowed_roots tracks the parent shell cwd, not the subshell cwd. cd into the first image directory at startup so uploads work from any caller cwd. - snapshot grep: case-insensitive match for the [Snapshot] header. - upload failure detection: use exit code plus specific error strings, not a loose grep that false-positives on 'Console: N errors'. - grep -c vs grep -o: the textarea may contain multiple URLs on a single line, so line-count undercounts. Switch to grep -o | wc -l. - --session requires --persistent on open to avoid silently dropping the on-disk user-data-dir. Bumps VERSION to 0.7.0.
- Drop the archive banner. gh-attach is back and actively solves two real problems (SSO re-auth, GHE React UI). - Document --session / --keep-session / --url-only with an end-to-end SAML example. - Call out that Direct mode does not work on GHE yet. Users must pass --browser on GHE. - Explain the allowed-roots constraint and the cd-to-first-image behaviour so File access denied errors are self-serviceable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Revives gh-attach (previously archived) to solve two recurring pain points:
session-stoptore down thebrowser between every invocation, so session-only cookies (e.g. OneLogin
"remember this device") died on exit. Add
--session <name>+--keep-sessionso a single persistent playwright-cli session canserve many uploads. One login in the morning, rest of the day is free.
file-attachmentcustom element with a React implementation. Direct mode does not work
there because the custom element never appears. Fix Browser mode to
work on GHE:
textarea.value(not accessibility snapshotsrcattribute).snapshot).
Also adds
--url-only: prints uploaded asset URLs to stdout and skipscomment creation/update so callers can post their own comment via
gh pr review --comment --body-fileor similar.Other fixes bundled in
allowed_rootsfollows the parentshell's cwd.
cdinto the first image's parent so uploads work fromany caller cwd.
[Snapshot]match.File access denied/ENOENTstrings, not a loosegrep errorthat false-positives on"Console: N errors".grep -c→grep -o | wc -l: the textarea can hold multiple URLs ona single line.
--sessionforces--persistenton open so the named session'son-disk user-data-dir is not silently replaced by an in-memory one.
README rewritten to reflect the new capabilities and drop the archive
notice.
Bumps VERSION to 0.7.0.
Test plan
Tested against a GHE instance (git.pepabo.com, React UI, behind OneLogin
SAML) on a closed test issue.
user-attachments/assets/<uuid>URLto stdout and exits 0
gh attach --helplists--session,--keep-session,--url-onlybash -n bin/gh-attachpasses syntax checktheir current behaviour on github.com (not regression-tested end to
end in this branch; smoke-tested via help output and script structure)