Skip to content

About

Chrome extension that shows live GitHub PR and issue state badges next to links in Slack web

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

slack-gh-badges

A Chrome extension that shows the live state of GitHub pull requests and issues next to every link to them in Slack web (app.slack.com).

State badges next to GitHub links in a Slack channel (sample data)

Slack's GitHub link previews show state only as a colored bar, and only when the preview appears. This extension adds a text badge with an icon, fetched fresh from the GitHub API:

Pull requests Issues
Open, Draft, Approved, Changes requested, Conflicts, Merged, Closed Open, Closed, Not planned

An open PR with merge conflicts shows only Conflicts, even when it is approved or a draft.

What gets a badge

Links to a GitHub PR or issue, whatever the visible text: https://github.com/…, http://…, and www.github.com/… (including /files, /changes, and comment anchors). The message composer is skipped.

Plain-text refs such as owner/repo#12 get no badge. A badge for one would have to go inside Slack's message text, which Slack's React rendering owns, and changing that text can garble a message when it is edited.

Install

  1. Clone this repo.
  2. Open chrome://extensions and turn on Developer mode.
  3. Click Load unpacked and select the repo folder.
  4. Open the extension's Details → Extension options. Paste a token and click Save, then Test.
  5. Reload your Slack tab.

To use Slack in its own window instead of a tab, open app.slack.com in Chrome and choose Cast, save, and share → Install page as app. The extension runs there too.

Token

Without a token, only public repos work, at GitHub's unauthenticated limit of 60 requests an hour.

For private repos, create a fine-grained personal access token:

  • Resource owner: the user or org that owns the repos.
  • Repository access: only the repos you reference in Slack.
  • Permissions: Pull requests: Read, Issues: Read, Metadata: Read. Nothing else.
  • Expiration: set one.

Some orgs require an admin to approve fine-grained tokens. Until then, their repos show No access.

Privacy

  • The token is stored in chrome.storage.local and read only by the service worker (background.js) and the options page. The script that runs on the Slack page never receives it, and the extension restricts chrome.storage.local to trusted extension contexts, so that script cannot read it either (Chrome 102 and later).
  • The extension sends requests only to api.github.com. It sends nothing to any other server and collects no data.
  • Icons are bundled in icons.js. Nothing else is loaded from the network.

Behaviour and limits

  • Works in Slack web in Chrome only, not in the Slack desktop or mobile apps.
  • Results are cached for 2 minutes per PR or issue. A badge does not change while the message is on screen; reload Slack to refresh it.
  • Failed lookups are cached too: 2 minutes for "not found" or "no access", and until the reset time when GitHub's rate limit is spent. Network failures are not cached.
  • An open PR costs 2 API calls (PR and reviews). The limit with a token is 5,000 calls an hour.
  • Approved and Changes requested use the latest review from each reviewer.
  • Conflicts comes from GitHub's mergeable_state, which GitHub computes in the background. While that state is still unknown, the result is cached for only 10 seconds, so the next re-render checks again.
  • The badges depend on Slack rendering normal <a href> links. A Slack redesign can break them.

Development

npm install
npm test            # unit tests and a simulated Slack page (jsdom)
npm run test:live   # also calls the real GitHub API, unauthenticated
npm run icons       # regenerate icons.js from lucide-static

License

MIT, see LICENSE. Icons are from Lucide under the ISC license, see THIRD_PARTY_LICENSES.

About

Chrome extension that shows live GitHub PR and issue state badges next to links in Slack web

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages