Python github.GitHub() Examples

The following are 12 code examples of github.GitHub(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module github , or try the search function .
Example #1
Source File: app.py    From open-source-library-data-collector with MIT License 6 votes vote down vote up
def update(send_email=True):
    # Update the DB with the GitHub repo data
    for repo in config.github_repos:
        github.update_library_data(config.github_user, repo)

    # Update the DB with Package Manager data
    pm.update_package_manager_data(config.package_manager_urls)

    # Export tables as CSV if config file indicates to do so
    if config.export_github:
        db.export_table_to_csv(GitHubData)
    if config['export_tables']['PackageManagers']:
        db.export_table_to_csv(PackageManagerData)

    if not send_email:
        return

    # Send an email update
    sg.send_email(config.to_email,
                  config.from_email,
                  config.email_subject,
                  config.email_body) 
Example #2
Source File: cron.py    From sample-platform with ISC License 6 votes vote down vote up
def cron(testing=False):
    """Script to run from cron for Sampleplatform."""
    from mod_ci.controllers import start_platforms, kvm_processor, TestPlatform
    from flask import current_app
    from run import config, log
    from database import create_session
    from github import GitHub

    log.info('Run the cron for kicking off CI platform(s).')
    # Create session
    db = create_session(config['DATABASE_URI'])
    gh = GitHub(access_token=config['GITHUB_TOKEN'])
    repository = gh.repos(config['GITHUB_OWNER'])(config['GITHUB_REPOSITORY'])

    if testing is True:
        kvm_processor(current_app._get_current_object(), db, config.get('KVM_LINUX_NAME', ''), TestPlatform.linux,
                      repository, None)
    else:
        start_platforms(db, repository) 
Example #3
Source File: controllers.py    From sample-platform with ISC License 6 votes vote down vote up
def inform_mailing_list(mailer, id, title, author, body) -> None:
    """
    Send mail to subscribed users when a issue is opened via the Webhook.

    :param mailer: The mailer instance
    :type mailer: Mailer
    :param id: ID of the Issue Opened
    :type id: int
    :param title: Title of the Created Issue
    :type title: str
    :param author: The Authors Username of the Issue
    :type author: str
    :param body: The Content of the Issue
    :type body: str
    """
    from run import get_github_issue_link

    subject = f"GitHub Issue #{id}"
    url = get_github_issue_link(id)
    if not mailer.send_simple_message({
        "to": "ccextractor-dev@googlegroups.com",
        "subject": subject,
        "html": get_html_issue_body(title=title, author=author, body=body, issue_number=id, url=url)
    }):
        g.log.error('failed to send issue to mailing list') 
Example #4
Source File: github_commits.py    From services-to-wordcloud with MIT License 6 votes vote down vote up
def authenticate(self):
        """
            (class) -> boolean

            Passing throught authentication and verifying if the right credentials were given.
        """

        if self.personal_access_token is not None:
            self.gh = github.GitHub(access_token = self.personal_access_token)
        else:
            self.gh = github.GitHub(
                        self.consumer_key,
                        self.consumer_secret,
                        self.access_token,
                        self.access_secret)
        try:
            
            some_get = self.gh.users(self.user_name).get()
            print json.dumps(some_get, sort_keys=True, indent=4, separators=(',', ': '))
            return True
        except Exception, ex:
            print '[e] exception {}'.format(str(ex))
            return False 
Example #5
Source File: __main__.py    From github-traffic-stats with Apache License 2.0 6 votes vote down vote up
def mergeCloneData(cloneStats, rid):
    # convert traffic data into SQL values
    data=""
    for cday in cloneStats['clones']:
        data+="("+str(rid)+",'"+cday['timestamp'][:10]+"',"+str(cday['count'])+","+str(cday['uniques'])+"),"
    mergeStatement=mergeClones1+data[:-1]+mergeClones2
    # execute MERGE statement
    res=ibm_db.exec_immediate(conn,mergeStatement)


# Overall flow:
# - loop over users
#   - log in to GitHub as that current user
#   - retrieve repos for that current user, loop the repos
#     - for each repo fetch stats
#     - merge traffic data into table
#  update last run info 
Example #6
Source File: asyncio_example.py    From uplink with MIT License 5 votes vote down vote up
def get_contributors(full_name):
    print("Getting GitHub repository `{}`".format(full_name))
    response = yield from gh_async.get_contributors(*full_name.split("/"))
    json = yield from response.json()
    print("response for {}: {}".format(full_name, json))
    return json 
Example #7
Source File: twisted_example.py    From uplink with MIT License 5 votes vote down vote up
def get_contributors(full_name):
    print("Getting GitHub repository `{}`".format(full_name))
    response = yield gh_async.get_contributors(*full_name.split("/"))
    json = response.json()
    print("response for {}: {}".format(full_name, json)) 
Example #8
Source File: test.py    From open-source-library-data-collector with MIT License 5 votes vote down vote up
def setUp(self):
        if os.environ.get('TRAVIS') is None:
            self.github = GitHub()
            self.db = DBConnector()
            self.config = Config() 
Example #9
Source File: test.py    From open-source-library-data-collector with MIT License 5 votes vote down vote up
def setUp(self):
        if os.environ.get('TRAVIS') is None:
            self.github = GitHub()
            self.db = DBConnector()
            self.config = Config()
            self.github.update_library_data(self.config.github_user,
                                            self.config.github_repos[0])
            self.filename = "./csv/{}.csv".format(GitHubData.__tablename__) 
Example #10
Source File: github_commits.py    From services-to-wordcloud with MIT License 5 votes vote down vote up
def get_commits(self):
        """
            (class) -> None

            Getting commits of the particular repository of the GitHub.
        """

        counter = 0
        page = 1

        # one exta requrest to understand math pages commits per page
        commits = self.gh.repos(self.user_name)(self.repository_name).commits.get(author = self.user_name, page = page)
        max_commits_per_page = len(commits)

        while True:
            commits = self.gh.repos(self.user_name)(self.repository_name).commits.get(author = self.user_name, page = page)
            for index in range(len(commits)):
                 commit_message = self.__get_replaced(commits[index]['commit'])
                 commit_date = self.__get_date(commits[index]['commit'])
                 self.df.loc[counter,'githubCommitMessage'] = commit_message
                 self.df.loc[counter,'timestamp'] = commit_date
                 counter += 1

            if max_commits_per_page == len(commits):
                page+=1
            else:
                break 
Example #11
Source File: controllers.py    From sample-platform with ISC License 4 votes vote down vote up
def queue_test(db, gh_commit, commit, test_type, branch="master", pr_nr=0) -> None:
    """
    Store test details into Test model for each platform, and post the status to GitHub.

    :param db: Database connection.
    :type db: sqlalchemy.orm.scoped_session
    :param gh_commit: The GitHub API call for the commit. Can be None
    :type gh_commit: Any
    :param commit: The commit hash.
    :type commit: str
    :param test_type: The type of test
    :type test_type: TestType
    :param branch: Branch name
    :type branch: str
    :param pr_nr: Pull Request number, if applicable.
    :type pr_nr: int
    :return: Nothing
    :rtype: None
    """
    from run import log

    fork_url = f"%/{g.github['repository_owner']}/{g.github['repository']}.git"
    fork = Fork.query.filter(Fork.github.like(fork_url)).first()

    if test_type == TestType.pull_request:
        log.debug('pull request test type detected')
        branch = "pull_request"

    linux_test = Test(TestPlatform.linux, test_type, fork.id, branch, commit, pr_nr)
    db.add(linux_test)
    windows_test = Test(TestPlatform.windows, test_type, fork.id, branch, commit, pr_nr)
    db.add(windows_test)
    db.commit()
    add_customized_regression_tests(linux_test.id)
    add_customized_regression_tests(windows_test.id)

    if gh_commit is not None:
        status_entries = {
            linux_test.platform.value: linux_test.id,
            windows_test.platform.value: windows_test.id
        }
        for platform_name, test_id in status_entries.items():
            try:
                gh_commit.post(
                    state=Status.PENDING,
                    description="Tests queued",
                    context=f"CI - {platform_name}",
                    target_url=url_for('test.by_id', test_id=test_id, _external=True)
                )
            except ApiError as a:
                log.critical(f'Could not post to GitHub! Response: {a.response}')

    log.debug("Created tests, waiting for cron...") 
Example #12
Source File: controllers.py    From sample-platform with ISC License 4 votes vote down vote up
def progress_reporter(test_id, token):
    """
    Handle the progress of a certain test after validating the token. If necessary, update the status on GitHub.

    :param test_id: The id of the test to update.
    :type test_id: int
    :param token: The token to check the validity of the request.
    :type token: str
    :return: Nothing.
    :rtype: None
    """
    from run import config, log

    test = Test.query.filter(Test.id == test_id).first()
    if test is not None and test.token == token:
        repo_folder = config.get('SAMPLE_REPOSITORY', '')

        if 'type' in request.form:
            if request.form['type'] == 'progress':
                log.info('[PROGRESS_REPORTER] Progress reported')
                if not progress_type_request(log, test, test_id, request):
                    return "FAIL"

            elif request.form['type'] == 'equality':
                log.info('[PROGRESS_REPORTER] Equality reported')
                equality_type_request(log, test_id, test, request)

            elif request.form['type'] == 'logupload':
                log.info('[PROGRESS_REPORTER] Log upload')
                if not upload_log_type_request(log, test_id, repo_folder, test, request):
                    return "EMPTY"

            elif request.form['type'] == 'upload':
                log.info('[PROGRESS_REPORTER] File upload')
                if not upload_type_request(log, test_id, repo_folder, test, request):
                    return "EMPTY"

            elif request.form['type'] == 'finish':
                log.info('[PROGRESS_REPORTER] Test finished')
                finish_type_request(log, test_id, test, request)
            else:
                return "FAIL"

            return "OK"

    return "FAIL"