GitHub SDK Integration

The Sym SDK provides convenience methods for interacting with GitHub in your impl.py.

๐Ÿ“˜

Did you configure your GitHub Integration?

Before continuing, make sure you followed the instructions on the main GitHub page to set up your GitHub credentials and Integration.

Before continuing, you will need to have:

  • Connected Sym with AWS Secrets Manager
  • Configured your GitHub Credentials with Sym
  • Defined a GitHub Integration resource

Add Your GitHub Integration to your Environment

If you are writing an impl.py for your GitHub Access Strategy, then your GitHub Integration will be implicitly available, and you can use the SDK methods without additional configuration.

However, if you wish to use the GitHub SDK methods in a different Flow (e.g. an Approval-Only Flow), then you must specify the Integration in your Environment.

resource "sym_environment" "this" {
  name            = "main"
  error_logger_id = sym_error_logger.slack.id

  integrations = {
    slack_id = sym_integration.slack.id

    # This is required to use GitHub SDK methods in impl.py
    # for non-GitHub strategies.
    github_id = sym_integration.github.id
  }
}

Using GitHub in your Flows

For more information on the supported methods in the github module, please visit the Sym SDK GitHub Docs.

Example implementations

Only repository admins can approve requests

from sym.sdk.annotations import reducer, hook
from sym.sdk.integrations import slack, github
from sym.sdk.templates import ApprovalTemplate


@hook
def on_approve(event):
    # Get the repository name from the target
    repo = event.payload.fields["target"].settings["repo_name"]

    # Get all users with the role "admin" in the requested repo
    admins = github.get_repo_collaborators(repo_name=repo, roles={'admin'})

    # Only allow users who are admins to approve.
    if event.user not in admins:
        return ApprovalTemplate.ignore(message="Only repo admins can approve requests")