code_corps v0.0.1 CodeCorps.GitHub.Sync.GithubAppInstallation View Source

Link to this section Summary

Functions

Tries to sync a GithubAppInstallation record using a Github API payload

Link to this section Types

Link to this type outcome() View Source
outcome() ::
  commit_result() |
  {:error, :multiple_unprocessed_installations_found}

Link to this section Functions

Link to this function sync(payload) View Source
sync(map()) :: outcome()

Tries to sync a GithubAppInstallation record using a Github API payload.

The process is branching.

If the installation can be matched by github id, then it is simply updated.

If the installation cannot be matched by github id, then the system tries to locate the user, through the sender github id.

If that fails, an unassociated installation is created.

If a user is found, the system looks for a “skeleton” installation. This is a CodeCorps.GithubAppInstallation record which was created from the project integration page, but the webhook for the next step, which is actually performing the installation on Github.com, has not yet been done.

This “skeleton” record is associated to a project and a user, but does not have any github data yet.

In this case, the system assumes a single “skeleton” installation. If multiple are found, an error tuple is returned.

If an installation is matched this way, it gets updated.

Finally, if no installation has been matched in this alternative way, an installation associated to a user, but not associated to a project gets created.