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

Link to this type comment_deleted_outcome() View Source
comment_deleted_outcome() :: {:ok, map()}
Link to this type installation_event_outcome() View Source
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()}
Link to this type installation_repositories_event_outcome() View Source
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()}
Link to this type issue_comment_outcome() View Source
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()}
Link to this type issue_event_outcome() View Source
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()}
Link to this type pull_request_comment_outcome() View Source
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()}
Link to this type pull_request_event_outcome() View Source
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

Link to this function installation_event(payload) View Source
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

Link to this function installation_repositories_event(payload) View Source
installation_repositories_event(map()) :: installation_repositories_event_outcome()

Syncs a GitHub InstallationRepositories event.

https://developer.github.com/v3/activity/events/types/#installationrepositoriesevent

Link to this function issue_comment_event(payload) View Source
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
  • 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

https://developer.github.com/v3/activity/events/types/#issuecommentevent

Link to this function issue_event(payload) View Source
issue_event(map()) :: issue_event_outcome()

Syncs a GitHub Issues event.

https://developer.github.com/v3/activity/events/types/#issuesevent

Link to this function pull_request_event(payload) View Source
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

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 GithubPullRequest records (and their related GithubUser records)
  • Fetches the issues from the API
  • Creates or updates GithubIssue records, and relates them to any related GithubPullRequest records created previously (along with any related GithubUser records)
  • Fetches the comments from the API
  • Creates or updates GithubComment records (and their related GithubUser records)
  • Creates or updates User records for the GithubUser records
  • Creates or updates Task records, and relates them to any related GithubIssue and User records created previously
  • Creates or updates Comment records, and relates them to any related GithubComment and User records created previously