Lightning.VersionControl (Lightning v2.19.0-pre)
View SourceBoundary module for handling Version control activities for project, jobs workflows etc Use this module to create, modify and delete connections as well as running any associated sync jobs
Summary
Functions
Creates a connection between a project and a github repo
Deletes the authorization for the github app and updates the user details accordingly
Fetches the oauth access token using the code received from the callback url For more info: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app
Fetches a repository's branches for user.
Fecthes the access token for the given User.
If the access token has expired, it refreshes the token and updates the User column accordingly
Fires the GitHub Action that pulls the project spec and commits it.
Checks if the given token has expired.
GitHub supports access tokens that expire and those that don't.
If the access token expires, then a refresh token is also availed.
This function simply checks if the token has a refresh_token, if yes, it proceeds to check the expiry date
Fetches a new access token using the given refresh token For more info: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens
Deletes a github connection
See Lightning.VersionControl.Events.subscribe/1.
Functions
@spec create_github_connection(map(), Lightning.Accounts.User.t()) :: {:ok, Lightning.VersionControl.ProjectRepoConnection.t()} | {:error, Ecto.Changeset.t() | Lightning.Extensions.UsageLimiting.message() | binary()}
Creates a connection between a project and a github repo
@spec delete_github_oauth_grant(Lightning.Accounts.User.t()) :: {:ok, Lightning.Accounts.User.t()} | {:error, map()}
Deletes the authorization for the github app and updates the user details accordingly
Fetches the oauth access token using the code received from the callback url For more info: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app
Fetches a repository's branches for user.
The GitHub App private key can mint an installation token for any
installation of the shared App, so this verifies (using the user's own GitHub
OAuth grant, via /user/installations) that installation_id is one the user
can access before using the app credential. Without this check a user could
read branch names from a private repository in another tenant's installation
(a confused-deputy). GitHub's installation token then scopes repository access
to that installation.
@spec fetch_user_access_token(Lightning.Accounts.User.t()) :: {:ok, String.t()} | {:error, map()}
Fecthes the access token for the given User.
If the access token has expired, it refreshes the token and updates the User column accordingly
@spec initiate_sync( repo_connection :: Lightning.VersionControl.ProjectRepoConnection.t(), commit_message :: String.t() ) :: :ok | {:error, Lightning.Extensions.UsageLimiting.message() | map() | binary()}
Fires the GitHub Action that pulls the project spec and commits it.
The export runs here first and its result is thrown away. The Action fetches
/api/provision/:id.yaml, and a 400 there lands in a GitHub Actions log
Lightning cannot read, so the user sees a sync that failed with no reason.
Costs one extra full spec generation on every successful sync.
Checks if the given token has expired.
GitHub supports access tokens that expire and those that don't.
If the access token expires, then a refresh token is also availed.
This function simply checks if the token has a refresh_token, if yes, it proceeds to check the expiry date
@spec reconfigure_github_connection( Lightning.VersionControl.ProjectRepoConnection.t(), map(), Lightning.Accounts.User.t() ) :: :ok | {:error, Lightning.Extensions.UsageLimiting.message() | map() | binary()}
Fetches a new access token using the given refresh token For more info: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens
Deletes a github connection
@spec save_oauth_token(Lightning.Accounts.User.t(), map(), [{:notify, boolean()}]) :: {:ok, Lightning.Accounts.User.t()} | {:error, Ecto.Changeset.t()}
See Lightning.VersionControl.Events.subscribe/1.
@spec verify_github_connection( repo_connection :: Lightning.VersionControl.ProjectRepoConnection.t() ) :: :ok | {:error, Lightning.VersionControl.GithubError.t() | map()}