Skip to content

Add Spring Boot GitHub helper library for PAT storage and commit/PR resolution - #1

Draft
pconrad with Copilot wants to merge 4 commits into
mainfrom
copilot/create-github-helper-library
Draft

Add Spring Boot GitHub helper library for PAT storage and commit/PR resolution#1
pconrad with Copilot wants to merge 4 commits into
mainfrom
copilot/create-github-helper-library

Conversation

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown

This introduces lib-github-helper as a Spring Boot dependency that can store an encrypted GitHub fine-grained PAT and expose GitHub metadata endpoints for recent main commits, open PR commits, and SHA-to-branch/PR resolution. The library is designed to support deployed-commit inspection flows, including mapping a SHA to expressions like main~3 or feature-branch~2.

  • Spring Boot starter structure

    • Adds Maven packaging, auto-configuration, and classpath registration for the library.
    • Ships a minimal JPA-backed module under edu.ucsb.cs156.githubhelper with controller, services, repository, and models.
  • Encrypted PAT storage

    • Adds a github_pats table and GithubPat entity for persisted PATs plus optional expiration.
    • Adds PatEncryptionService and GithubPatService to encrypt at rest and retrieve the latest non-expired token.
    • Exposes POST /api/githubhelper/pat for uploading a token and optional expiration timestamp.
  • GitHub helper endpoints

    • Adds GET /api/githubhelper/prs/{owner}/{repo} to return:
      • recent commits on the configured main branch
      • open PRs with title, URL, branch name, and commit list
    • Adds GET /api/githubhelper/commit/{owner}/{repo}/{sha} to classify a SHA as:
      • current main
      • historical main~N
      • current open PR head
      • historical PR branch commit branch~N
      • no match
  • Response model for frontend integration

    • Defines explicit JSON models for:
      • main-branch snapshots
      • PR commit snapshots
      • SHA match results with branch expression, distance, and PR metadata when applicable
  • Documentation

    • Expands the README with:
      • JitPack/Spring Boot installation instructions modeled after lib-jobs
      • required encryption properties and Liquibase include
      • instructions for creating a public-information fine-grained PAT
      • example JSON payloads for the new endpoints

Example response shape for commit lookup:

{
  "owner": "ucsb-cs156",
  "repo": "lib-github-helper",
  "sha": "012def",
  "matched": true,
  "matches": [
    {
      "kind": "pull_request",
      "branchName": "feature-branch",
      "expression": "feature-branch~1",
      "distance": 1,
      "url": "https://github.com/ucsb-cs156/lib-github-helper/pull/12",
      "pullRequestNumber": 12,
      "pullRequestTitle": "Add feature"
    }
  ]
}
Original prompt

Please build a library that can be included as a Spring Boot dependency (see https://github.com/ucsb-cs156/lib-jobs and follow the conventions there).

This library should have:

  • A PAT encryption service (borrow the code from https://github.com/ucsb-cs156/proj-frontiers)
  • A database table to store Github PATs (borrow the code from https://github.com/ucsb-cs156/proj-frontiers)
  • A GithubHelperController with endpoints:
    • POST /api/githubhelper/pat that uploads a PAT and optionally it's expiration date
    • GET /api/githubhelper/prs/{owner}/{repo} that gets information about the last few commits on the main branch, and the commits on each open PR, and returns them in JSON format. For the PRs, we want title, url, list of commits (for each commit, the SHA and the commit message).
    • GET /api/githubhelper/commit/{owner}{repo}/sha} Takes a github repo and a SHA and returns information about that commit as specified below.

The readme should explain

  • how to install this in a SpringBoot application (model it after https://github.com/ucsb-cs156/lib-jobs )
  • how to obtain a fine-grained PAT that can only access public information (i.e. All Repos, and No Scopes).

Sample Instructions:

You can generate a PAT that can only access publicly available Github information by visiting your GitHub Developer Settings and creating a new fine-grained token with these settings:

  • Token name: Give it a descriptive name (e.g., "Public Read-Only").
  • Repository access: Select "All repositories".
  • Account/Repository Permissions: Leave all dropdowns at their default of "No access".
  • Click Generate token.

This is intended to be used in combination with the following module that gets information about the currently deployed commit:

                <groupId>io.github.git-commit-id</groupId>
                <artifactId>git-commit-id-maven-plugin</artifactId>
                <version>8.0.2</version>

That module allows a Spring Boot application to determine what commit was deployed to the app.

This module, via the GET /api/githubhelper/commit/{owner}{repo}/sha} endpoint, adds the ability to determine, for any given commit, whether that commit is:

  • the latest commit on the main branch
  • an earlier commit on the main branch (e.g.main1, main2, etc.)
  • a commit that is the latest commit on an open PR
  • a commit that is an earlier commit on an open PR (e.g. feature-branch1, feature-branch2, etc.)
  • none of the above.

That can give developers a way to quickly verify whether a deployment is up-to-date with what they think they are testing.

Please design and document an appropriate JSON format to return this information.

The intention is to be able to build a frontend that shows the developer:

  • The SHA of the deployed commit
  • The branch name that matches that SHA, if it is main or the branch name of an open PR, or if it is among the last 10 commits on the main branch, or any of the commits on an open PR, the branch name expression such as main3 or feature-branch2 that matches the commit.
  • When the SHA matches a PR, a link to the applicable PR.
  • When the SHA matches the main branch, a link to the repo.

Copilot AI changed the title [WIP] Add Github helper library for Spring Boot Add Spring Boot GitHub helper library for PAT storage and commit/PR resolution Jul 14, 2026
Copilot AI requested a review from pconrad July 14, 2026 16:06
@pconrad

pconrad commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@copilot to avoid scope issues with the table, let's prefix the table names with github_helper_.

Otherwise, they may conflict with table names that are already in the applications.

Also: we will need to think about how liquibase database migrations work when adopting this library. Do we need to add instructions to copy a particular database migration into the proper place? Or is there a way for libraries like this to manage their own tables with some kind of "hook" into liquibase? What is best practice for this situation?

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Author

@copilot to avoid scope issues with the table, let's prefix the table names with github_helper_.

Otherwise, they may conflict with table names that are already in the applications.
...

Addressed in 1a62c80: the PAT table is now namespaced as github_helper_pats in both JPA and the bundled Liquibase changelog. I also updated the README with the recommended Liquibase pattern for this library: ship the changelog in the jar and have the consuming app include it from its own master changelog rather than copying the migration file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants