code_corps v0.0.1 CodeCorps.GitHub.Sync View Source
GitHub syncing functions for:
- events received from the GitHub API
- entire GitHub repositories
Link to this section Summary
Functions
Handles a GitHub installation event
Syncs a GitHub InstallationRepositories event
Syncs a GitHub IssueComment event
Syncs a GitHub Issues event
Syncs a GitHub PullRequest event
Syncs a GithubRepo
Link to this section Types
installation_event_outcome() :: {:ok, CodeCorps.GithubAppInstallation.t()} | {:error, :validation_error_on_syncing_installation, Ecto.Changeset.t()} | {:error, :multiple_unprocessed_installations_found} | {:error, :github_api_error_on_syncing_repos, struct()} | {:error, :validation_error_on_deleting_removed_repos, {list(), list()}} | {:error, :validation_error_on_syncing_existing_repos, {list(), list()}} | {:error, :validation_error_on_marking_installation_processed, Ecto.Changeset.t()} | {:error, :unexpected_transaction_outcome, any()}
installation_repositories_event_outcome() :: {:ok, [CodeCorps.GithubRepo.t()]} | {:error, :unmatched_installation} | {:error, :validation_error_on_syncing_repos, Ecto.Changeset.t()} | {:error, :unexpected_transaction_outcome, any()}
issue_comment_outcome() :: {:ok, CodeCorps.Comment.t()} | {:error, :repo_not_found} | {:error, :validating_github_issue, Ecto.Changeset.t()} | {:error, :validating_github_user_on_github_issue, Ecto.Changeset.t()} | {:error, :validating_task_user, Ecto.Changeset.t()} | {:error, :multiple_task_users_match} | {:error, :validating_task, Ecto.Changeset.t()} | {:error, :validating_github_comment, Ecto.Changeset.t()} | {:error, :validating_github_user_on_github_comment, Ecto.Changeset.t()} | {:error, :validating_comment_user, Ecto.Changeset.t()} | {:error, :multiple_comment_users_match} | {:error, :validating_comment, Ecto.Changeset.t()} | {:error, :unexpected_transaction_outcome, any()}
issue_event_outcome() :: {:ok, CodeCorps.Task.t()} | {:error, :repo_not_found} | {:error, :validating_github_issue, Ecto.Changeset.t()} | {:error, :validating_user, Ecto.Changeset.t()} | {:error, :multiple_task_users_match} | {:error, :validating_task, Ecto.Changeset.t()} | {:error, :unexpected_transaction_outcome, any()}
pull_request_comment_outcome() :: issue_comment_outcome() | {:error, :fetching_pull_request, struct()} | {:error, :validating_github_pull_request, Ecto.Changeset.t()} | {:error, :validating_github_user_on_github_pull_request, Ecto.Changeset.t()}
pull_request_event_outcome() :: {:ok, map()} | {:error, :repo_not_found} | {:error, :fetching_issue, struct()} | {:error, :validating_github_pull_request, Ecto.Changeset.t()} | {:error, :validating_github_issue, Ecto.Changeset.t()} | {:error, :validating_user, Ecto.Changeset.t()} | {:error, :multiple_issue_users_match} | {:error, :validating_task, Ecto.Changeset.t()} | {:error, :unexpected_transaction_outcome, any()}
Link to this section Functions
installation_event(map()) :: installation_event_outcome()
Handles a GitHub installation event.
Currently only supports the “added” version of the event.
The event is handled by first syncing the installation payload into a new or
existing CodeCorps.GithubAppInstallation record, using
CodeCorps.GitHub.Sync.Installation.sync/1, followed by syncing the
record’s CodeCorps.GithubRepo children using
CodeCorps.GitHub.Sync.Repo.sync_installation/1.
https://developer.github.com/v3/activity/events/types/#installationevent
installation_repositories_event(map()) :: installation_repositories_event_outcome()
Syncs a GitHub InstallationRepositories event.
For the “removed” action:
- Deletes all
CodeCorps.GithubReporecords matched with the payload
- Deletes all
For the “added” action:
- Adds all
CodeCorps.GithubReporecords matching data from the payload
- Adds all
https://developer.github.com/v3/activity/events/types/#installationrepositoriesevent
issue_comment_event(map()) :: issue_comment_event_outcome()
Syncs a GitHub IssueComment event.
For the deleted action
- Deletes the related comment records with
Sync.Comment
- Deletes the related comment records with
For any other action
- Finds the
CodeCorps.GithubRepo - If it’s a pull request, it fetches the pull request from the GitHub API
and syncs it with
Sync.PullRequest - Syncs the issue portion of the event with
Sync.Issue - Syncs the comment portion of the event with
Sync.Comment
- Finds the
https://developer.github.com/v3/activity/events/types/#issuecommentevent
Syncs a GitHub Issues event.
- Finds the
CodeCorps.GithubRepo - Syncs the issue portion of the event with
Sync.Issue
https://developer.github.com/v3/activity/events/types/#issuesevent
pull_request_event(map()) :: pull_request_event_outcome()
Syncs a GitHub PullRequest event.
- Finds the
CodeCorps.GithubRepo - Fetches the issue from the GitHub API
- Syncs the pull request portion of the event with
Sync.PullRequest - Syncs the issue portion of the event with
Sync.Issue, using the changes passed in from the issue fetching and the pull request syncing
https://developer.github.com/v3/activity/events/types/#pullrequestevent
sync_repo(CodeCorps.GithubRepo.t()) :: {:ok, CodeCorps.GithubRepo.t()} | {:error, Ecto.Changeset.t()}
Syncs a GithubRepo.
Fetches and syncs records from the GitHub API for a given repository, marking progress of the sync state along the way.
- Fetches the pull requests from the API
- Creates or updates
GithubPullRequestrecords (and their relatedGithubUserrecords) - Fetches the issues from the API
- Creates or updates
GithubIssuerecords, and relates them to any relatedGithubPullRequestrecords created previously (along with any relatedGithubUserrecords) - Fetches the comments from the API
- Creates or updates
GithubCommentrecords (and their relatedGithubUserrecords) - Creates or updates
Userrecords for theGithubUserrecords - Creates or updates
Taskrecords, and relates them to any relatedGithubIssueandUserrecords created previously - Creates or updates
Commentrecords, and relates them to any relatedGithubCommentandUserrecords created previously