Lightning.VersionControl (Lightning v2.13.4)

View Source

Boundary 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

Fecthes the access token for the given User. If the access token has expired, it refreshes the token and updates the User column accordingly

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

See Lightning.VersionControl.Events.subscribe/1.

Functions

create_github_connection(attrs, user)

Creates a connection between a project and a github repo

delete_github_oauth_grant(user)

@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

exchange_code_for_oauth_token(code)

@spec exchange_code_for_oauth_token(code :: String.t()) ::
  {:ok, map()} | {:error, map()}

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

fetch_installation_repos(installation_id)

fetch_repo_branches(installation_id, repo_name)

fetch_user_access_token(user)

@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

fetch_user_installations(user)

get_repo_connection_for_project(project_id)

get_repo_connection_for_token(token)

github_enabled?()

initiate_sync(repo_connection, commit_message)

@spec initiate_sync(
  repo_connection :: Lightning.VersionControl.ProjectRepoConnection.t(),
  commit_message :: String.t()
) :: :ok | {:error, Lightning.Extensions.UsageLimiting.message() | map()}

oauth_token_valid?(token)

@spec oauth_token_valid?(token :: map()) :: boolean()

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

reconfigure_github_connection(repo_connection, params, user)

refresh_oauth_token(refresh_token)

@spec refresh_oauth_token(refresh_token :: String.t()) ::
  {:ok, map()} | {:error, map()}

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

remove_github_connection(repo_connection, user)

Deletes a github connection

save_oauth_token(user, token, opts \\ [notify: true])

@spec save_oauth_token(Lightning.Accounts.User.t(), map(), [{:notify, boolean()}]) ::
  {:ok, Lightning.Accounts.User.t()} | {:error, Ecto.Changeset.t()}

subscribe(user)

See Lightning.VersionControl.Events.subscribe/1.

verify_github_connection(repo_connection)

@spec verify_github_connection(
  repo_connection :: Lightning.VersionControl.ProjectRepoConnection.t()
) ::
  :ok | {:error, Lightning.VersionControl.GithubError.t() | map()}