Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git(hub) integration feature #791

Open
wants to merge 16 commits into
base: refactor/metadata-generation
Choose a base branch
from

Conversation

sgfost
Copy link
Contributor

@sgfost sgfost commented Jan 9, 2025

this relies on changes in #790


part 1 (1-way mirror):

adds a button that allows model submitters to create an auto-updating, read-only git repository archive which is hosted on a central organization

the 'mirror' git repository consists of commits for each release that are tagged and branched off so that metadata can be updated for individual releases without re-writing history

additions

  • library.fs.CodebaseGitRepositoryApi: functionality for building/updating a git repository from a Codebase
  • library.github.GithubApi: provides an interface over PyGithub for interacting with repositories on github
  • library.github.GithubRepoNameValidator: provides validate() to make sure a repo name is valid and unused
  • mirror_codebase() and update_mirrored_codebase() huey tasks which call the CodebaseGitRepositoryApi to build the git repo on the file system and then GithubApi to create/push to the remote
  • update_mirrored_release_metadata() huey task which is triggered when there is an update to codemeta, and updates the corresponding release branch in git after the submission package is rebuilt
  • feature overview page at /github/
  • button + form on the release detail page for mirroring a codebase

configuration steps

  1. create an app on the comses-model-library organization with the following permissions:
    • Administration: read and write
    • Contents: read and write
    • Metadata: read only
  2. generate client secret and private key
  3. install the app on the organization and add the installation id to .env
  4. add the app id, client id, and organization name to .env
  5. add the private key and client secret to secrets/

@sgfost sgfost force-pushed the feat/git-mirroring branch from 73bee28 to b25ba7b Compare January 9, 2025 21:58
@sgfost sgfost changed the title git mirroring github integration - mirroring Jan 10, 2025
@sgfost sgfost force-pushed the feat/git-mirroring branch from b25ba7b to a64a05e Compare January 10, 2025 20:02
@sgfost sgfost force-pushed the refactor/metadata-generation branch from 17f1895 to 9cbc597 Compare January 14, 2025 00:23
@sgfost sgfost force-pushed the feat/git-mirroring branch from a64a05e to 81edfd5 Compare January 14, 2025 02:23
this API is responsible for managing a local git repository mirror for a
comses codebase. PUBLIC release archives are commits/tags in the
history. Release branches are created for each release and only added to
if there is an update to metadata

`build()` and `append_releases()` are the two main API methods which
construct (or rebuild) a git repo and add new releases to the repo,
respectively

`update_release_branch()` will add a new commit containing changes to a
release branch (and update main if they point to the same thing). This
will mainly be used for updating metadata
the GithubApi provides access to auth and repository actions

adds 3 huey (async) tasks for creating a mirror, updating a mirror, and
updating metadata for a single release of a mirror
* /github page to describe the integration features
* sidebar element on release detail page will show information about
  integration status for that codebase, and allow users with edit
  permissions to create a new mirror
@sgfost sgfost force-pushed the feat/git-mirroring branch 2 times, most recently from a92874c to 8c42b35 Compare January 23, 2025 00:10
sgfost referenced this pull request Jan 23, 2025
- include in .env PATH and make docker-compose.yml target depend on .env
- replace deprecated usage of self.assertEquals
https://docs.python.org/3/whatsnew/3.12.html#id3
@sgfost sgfost force-pushed the feat/git-mirroring branch from 8c42b35 to baed067 Compare January 25, 2025 01:42
* use installation access tokens for user repos instead of user access
  tokens. this is a more secure workflow
* add GithubIntegrationAppInstallation model for recording app
  installations (this will need to be created/updated using webhooks)
* CodebaseGitMirror/"mirror" now refers to the local git repository
* ^ can have multiple CodebaseGitRemote's which keep track of all the
  information needed to push to/archive from remote repositories

TODO: re-implement views
@sgfost sgfost force-pushed the feat/git-mirroring branch from baed067 to d3432cb Compare January 25, 2025 01:43
@sgfost sgfost changed the title github integration - mirroring git(hub) integration feature Jan 25, 2025
sgfost added 10 commits January 27, 2025 20:12
this replaces the simple modal form to give better control over the feature
The distinguishing feature is whether the release has a non-null
external_release_package

This will be used to 'archive' or pull in releases made on github for
synced repos

currently, the release assets/package is not stored on the filesystem,
instead relying on an external download url, and being only concerned
with metadata
App installation tokens did not give access to get/create repos on a
user's account. Still trying to avoid storing user access tokens
(https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app)
so as a workaround, we will direct the submitter to create a new bare
repo before continuing

* add handler for webhook events for the github sync app
* add form/wizard for linking a pre-existing github repo (archive only)
allows setting up a push/archive sync that will automatically have the
generated git repo pushed to by providing an empty repo, as well as
setting up an archive only sync by providing any github repo

in both cases, the submitter needs to:
- link their github account with the regular oauth flow
  (so we have a way to match users with a github account)
- install the provided 'GitHub Sync' app on their github account with
  access to any repository that will be synced
and squash migrations

"import(ing)" is the wording I keep finding describes the process the
best

other potential names and their issues:
* publish - same name as the direct publishing, releases need to be
  manually published after they are imported
* pull - git command that is not used
* fetch - git command that is not used
* ingest - ok and similar to import but not quite as clear
@sgfost sgfost force-pushed the feat/git-mirroring branch from b4786f6 to 8c05280 Compare February 13, 2025 17:58
* re-order and clarify the steps to set up a sync (app installation
  takes place after creating a repo so that permissions can be
  restricted)
* fix push log to actual show useful information
* when toggling push back on, do a build/update + push on the spot
* better error/success messages
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.

1 participant