Esempio n. 1
0
def get_installation_token(owner, repo, integration_id, private_key):
    integration = GithubIntegration(integration_id=int(integration_id),
                                    private_key=private_key)

    installation = integration.get_installation(owner, repo)

    return integration.get_access_token(installation.id.value).token
Esempio n. 2
0
 def test_get_installation(self):
     from github import GithubIntegration
     integr = GithubIntegration("11111", private_key)
     inst = integr.get_installation("foo", "bar")
     self.assertEqual(
         self.get_mock.calls[0][0],
         ('https://api.github.com/repos/foo/bar/installation', ))
     self.assertEqual(inst.id.value, 111111)
Esempio n. 3
0
 def test_get_installation_custom_base_url(self):
     from github import GithubIntegration
     integr = GithubIntegration("11111",
                                private_key,
                                base_url='https://corp.com/v3')
     inst = integr.get_installation("foo", "bar")
     self.assertEqual(self.get_mock.calls[0][0],
                      ('https://corp.com/v3/repos/foo/bar/installation', ))
     self.assertEqual(inst.id.value, 111111)
Esempio n. 4
0
def get_github():
    with open(GH_PRIVATE_KEY_PATH) as in_file:
        gh_integration = GithubIntegration(
            integration_id=47055, private_key=in_file.read()
        )

    installation = gh_integration.get_installation("ooni", "probe")
    access_token = gh_integration.get_access_token(
        installation_id=installation.id.value
    )
    return Github(login_or_token=access_token.token)
Esempio n. 5
0
    def github_instance(self):
        if not self._github_instance:
            if self.service.github_app_id and self.service.github_app_private_key:
                integration = GithubIntegration(
                    self.service.github_app_id,
                    self.service.github_app_private_key)
                inst_id = integration.get_installation(self.namespace,
                                                       self.repo).id.value
                inst_auth = integration.get_access_token(inst_id)
                self._github_instance = github.Github(
                    login_or_token=inst_auth.token)
            else:
                self._github_instance = self.service.github

        return self._github_instance
Esempio n. 6
0
def token(user, repo):
    with open(os.path.join(dir_path, 'app_id.txt'), 'r') as fh:
        app_id = int(fh.read())

    with open(os.path.join(dir_path, 'dev-desktop.private-key.pem'),
              'rb') as fh:
        private_key = fh.read()

    integration = GithubIntegration(app_id, private_key)

    installation = integration.get_installation(user, repo)

    auth = integration.get_access_token(installation.id)

    return auth.token
Esempio n. 7
0
    def github_instance(self):
        if not self._github_instance:
            if self.service.github_app_id and self.service.github_app_private_key:
                integration = GithubIntegration(
                    self.service.github_app_id,
                    self.service.github_app_private_key)
                inst_id = integration.get_installation(self.namespace,
                                                       self.repo).id.value
                if not inst_id:
                    raise OgrException(
                        f"No installation ID provided for {self.namespace}/{self.repo}: "
                        "please make sure that you provided correct credentials of your GitHub app."
                    )
                inst_auth = integration.get_access_token(inst_id)
                self._github_instance = github.Github(
                    login_or_token=inst_auth.token)
            else:
                self._github_instance = self.service.github

        return self._github_instance
Esempio n. 8
0
import os
import base64

from github import GithubIntegration

# Get the App
id = int(os.getenv("GITHUB_APP_ID"))
private_key = base64.b64decode(os.getenv("GITHUB_APP_PRIVATE_KEY"))
app = GithubIntegration(id, private_key)

# Get the installation
owner = os.getenv("GITHUB_OWNER")
repo = os.getenv("GITHUB_REPO")
installation = app.get_installation(owner, repo)

# Get an installation access token
tok = app.get_access_token(installation.id)

# Print the token to STDOUT
print(tok.token)
Esempio n. 9
0
 def test_get_installation(self):
     from github import GithubIntegration
     integr = GithubIntegration("11111", private_key)
     inst = integr.get_installation("foo", "bar")
     self.assertEqual(inst.id.value, 111111)
Esempio n. 10
0
import discord

from os import urandom
from github import Github, GithubIntegration
from src.defines import TOKEN, GUILD, TARGET_CHANNEL, GITHUB_APP_ID, GITHUB_CLIENT_ID
from src.input_proccesors.vote import Vote
from src.input_proccesors.suggestion import Suggestion

github_integration = GithubIntegration(GITHUB_APP_ID, open('angry-villager.2020-10-03.private-key.pem', 'r').read())
installation = github_integration.get_installation('OutlawByteStudios', 'KingdomsDiscordBot')
token = github_integration.create_jwt()


github_client = Github('v1.e9827ef3291f575ac58d4def4ab428afc868806e')
client = discord.Client()

# Suggestions project = 5594461
# Suggestions column = 11079851
# Project Plan project id = 5594457
project_kingdoms_suggestions_repo = github_client.get_repo(
    'OutlawByteStudios/KingdomsDiscordBot')
suggestion_column = github_client.get_project_column(11079851)
suggestion_label = project_kingdoms_suggestions_repo.get_label('suggestion')


vote = Vote(project_kingdoms_suggestions_repo)
suggestion = Suggestion(project_kingdoms_suggestions_repo,
                        suggestion_column, suggestion_label)

print(f'Repo has {project_kingdoms_suggestions_repo.open_issues} open issues')