starquery

package module
v0.0.0-...-7aab316 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 11 Imported by: 0

README

starquery

Query in near-realtime if a user has starred a GitHub repository.

https://starquery.coder.com/coder/coder/user/kylecarbs
  • Uses GitHub Webhooks for near-realtime accuracy.
  • Periodically refreshes all stargazers using GitHub's GraphQL API for accuracy.
  • Start tracking a repository by adding it to the list!

This service is used by coder/coder to prompt users to star the repository if they haven't already!

Deployment

starquery is hosted at starquery.coder.com. Not all repositories are tracked by default (that'd be a lot to handle!). Feel free to repositories here.

To run starquery, GITHUB_TOKEN and REDIS_URL are required. WEBHOOK_SECRET must be set if accepting Webhooks from GitHub's API.

Hosted

The ./deploy.sh script can be used to update the service (probably should be automated at some point).

/run/starquery/environ must exist. Here is a template:

REDIS_URL=127.0.0.1:6379
BIND_ADDRESS=127.0.0.1:8080
# use cdrci account
GITHUB_TOKEN=
WEBHOOK_SECRET=

To set up the Cloudflare Tunnel, see the config file. cloudflared is ran in screen -S cloudflared:

cloudflared tunnel run 7e5e3b0d-4eb3-4aff-9924-e5f6efebcc2d

To set up a GitHub webhook:

  1. Head to the "New Webhook" page (e.g. https://github.com/coder/starquery/settings/hooks/new).
  2. Set the payload URL to https://starquery.coder.com/webhook.
  3. Click "Let me select individual events.", uncheck "Push", check "Stars".

Delivery should succeed for the initial ping!

Documentation

Overview

Package starquery provides functionality to query and manage GitHub stargazers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API handles GitHub stargazer queries.

func New

func New(ctx context.Context, opts Options) *API

New creates a new API handler that fetches stargazers for the given repos.

func (*API) Close

func (a *API) Close()

Close shuts down the API and waits for all goroutines to finish.

func (*API) ServeHTTP

func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Options

type Options struct {
	Client        *http.Client
	KV            kv.Store
	Logger        *slog.Logger
	Repos         []Repo
	WebhookSecret string
}

Options holds configuration for the API.

type Repo

type Repo struct {
	Owner string
	Name  string
}

Repo represents a GitHub repository.

func (Repo) Key

func (r Repo) Key(username string) string

Key returns the storage key for the repo with the username.

func (Repo) String

func (r Repo) String() string

type Stargazer

type Stargazer struct {
	Login  string
	Cursor string
}

Stargazer stores the username and cursor of the user starring.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL