JuliusBrussee/caveman · error

githubapp: get repo installation

Error message

githubapp: get repo installation %s/%s: HTTP %d: %s

What it means

GetRepoInstallation asks GitHub which App installation owns access to a repo via GET /repos/{owner}/{name}/installation authenticated with a JWT, expecting HTTP 200. Non-200 statuses produce this error with owner/name, status, and body snippet.

Solutions

  1. Regenerate the App JWT just before the call — JWTs are valid only ~10 minutes (check iat/exp claims)
  2. Verify App ID and private key match the App that owns the installation (401)
  3. Confirm in GitHub App settings that the repo/org is included in the installation (404)
  4. On 403 check X-RateLimit headers and integration suspension status, retry after backoff

Example fix

// before
inst, err := app.GetRepoInstallation(ctx, owner, name)
if err != nil { return err }
// after
inst, err := app.GetRepoInstallation(ctx, owner, name)
if err != nil {
    if strings.Contains(err.Error(), "HTTP 401") {
        return fmt.Errorf("app JWT expired — regenerate before calling: %w", err)
    }
    return err
}
Defensive patterns

Strategy: retry

Validate before calling

// mint a fresh App JWT (<=10 min exp) immediately before the call
// verify appID > 0 and privateKey loaded
if appID == 0 || privateKey == nil { return errors.New("app credentials missing") }

Type guard

func isInstallAuthError(err error) bool { return err != nil && strings.Contains(err.Error(), "HTTP 401") }

Try / catch

inst, err := app.GetRepoInstallation(ctx, owner, name)
if err != nil {
    if isInstallAuthError(err) { return retryWithFreshJWT() } // regenerate JWT and retry once
    return err
}

Prevention

When it happens

Trigger: GET /repos/.../installation returns non-200: 404 when the App has no installation covering that repo, 401 when the App JWT is expired or malformed, 403 when the integration is suspended.

Common situations: JWT generated with wrong App ID or stale private key (expired after 10 minutes); repo not granted to the App installation; verifying control of a repo the App genuinely cannot access.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/f77727d0bc8e6c06. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/githubapp/githubapp.go:285

	return r, nil
}

// GetRepoInstallation asks GitHub which installation of this App owns access to
// a repository. This avoids treating public repository visibility as proof that
// a caller-supplied installation id is authorized for that repository.
func (a *App) GetRepoInstallation(ctx context.Context, owner, name string) (Installation, error) {
	var out Installation
	jwt, err := a.AppJWT()
	if err != nil {
		return out, err
	}
	status, raw, err := a.do(ctx, "Bearer "+jwt, http.MethodGet,
		"/repos/"+url.PathEscape(owner)+"/"+url.PathEscape(name)+"/installation", nil)
	if err != nil {
		return out, err
	}
	if status != http.StatusOK {
		return out, fmt.Errorf("githubapp: get repo installation %s/%s: HTTP %d: %s", owner, name, status, snippet(raw))
	}
	if err := json.Unmarshal(raw, &out); err != nil {
		return out, fmt.Errorf("githubapp: decode repo installation: %w", err)
	}
	if out.ID <= 0 {
		return Installation{}, fmt.Errorf("githubapp: repo installation response carried no id")
	}
	return out, nil
}

// GetFileContent reads one repository file with an installation token. The
// content endpoint returns base64; callers receive decoded bytes with a strict
// 64 KiB post-decode ceiling because connection proofs are tiny text files.
func (a *App) GetFileContent(ctx context.Context, token, owner, name, path, ref string) ([]byte, error) {
	segments := strings.Split(strings.Trim(path, "/"), "/")
	if len(segments) == 0 || segments[0] == "" {
		return nil, fmt.Errorf("githubapp: content path is required")
	}

View on GitHub (pinned to 3ee70a1026)