easybuild.tools.github module

Utility module for working with github

author:Jens Timmerman (Ghent University)
author:Kenneth Hoste (Ghent University)
author:Toon Willems (Ghent University)
exception easybuild.tools.github.GithubError

Bases: Exception

Error raised by the Githubfs

class easybuild.tools.github.Githubfs(githubuser, reponame, branchname=None, username=None, password=None, token=None)

Bases: object

This class implements some higher level functionality on top of the Github api

get_path(path)

returns the path as a Github object (from agithub)

get_repo()

Returns the repo as a Github object (from agithub)

static isdir(githubobj)

Check if this path points to a directory

static isfile(githubobj)

Check if this path points to a file

static join(*args)

This method joins ‘paths’ inside a github repository

listdir(path)

List the contents of a directory

read(path, api=True)

Read the contents of a file and return it Or, if api=False it will download the file and return the location of the downloaded file

walk(top=None, topdown=True)

Walk the github repo in an os.walk like fashion.

easybuild.tools.github.add_pr_labels(pr, branch='develop')

Try to determine and add labels to PR. :param pr: pull request number in easybuild-easyconfigs repo :param branch: easybuild-easyconfigs branch to compare with

easybuild.tools.github.check_github()

Check status of GitHub integration, and report back. * check whether GitHub username is available * check whether a GitHub token is available, and whether it works * check whether git and GitPython are available * check whether push access to own GitHub repositories works * check whether creating gists works * check whether location to local working directories for Git repositories is available (not strictly needed)

easybuild.tools.github.check_online_status()

Check whether we currently are online Return True if online, else a list of error messages

easybuild.tools.github.check_pr_eligible_to_merge(pr_data)

Check whether PR is eligible for merging.

Parameters:pr_data – PR data obtained through GitHub API
Returns:boolean value indicates whether PR is eligible
easybuild.tools.github.close_pr(pr, motivation_msg=None)

Close specified pull request

Parameters:
  • pr – PR number
  • motivation_msg – string containing motivation for closing the PR
easybuild.tools.github.create_gist(txt, fn, descr=None, github_user=None, github_token=None)

Create a gist with the provided text.

easybuild.tools.github.create_remote(git_repo, account, repo, https=False)

Create remote in specified git working directory for specified account & repository.

Parameters:
  • git_repo – git.Repo instance to use (after init_repo & setup_repo)
  • account – GitHub account name
  • repo – repository name
  • https – use https:// URL rather than git@
easybuild.tools.github.delete_gist(gist_id, github_user=None, github_token=None)

Delete gist with specified ID.

easybuild.tools.github.det_account_branch_for_pr(pr_id, github_user=None, pr_target_repo=None)

Determine account & branch corresponding to pull request with specified id.

easybuild.tools.github.det_commit_status(account, repo, commit_sha, github_user)

Determine status of specified commit (pending, error, failure, success)

We combine two different things here:

  • the combined commit status (Travis CI sets a commit status)
  • results of check suites (set by CI run in GitHub Actions)
easybuild.tools.github.det_patch_specs(patch_paths, file_info, ec_dirs)

Determine software names for patch files

easybuild.tools.github.det_pr_labels(file_info, pr_target_repo)

Determine labels for a pull request based on provided information on files changed by that pull request.

easybuild.tools.github.det_pr_target_repo(paths)

Determine target repository for pull request from given cagetorized list of files

Parameters:paths – paths to categorized lists of files (easyconfigs, files to delete, patches, .py files)
easybuild.tools.github.download_repo(repo='easybuild-easyconfigs', branch=None, account='easybuilders', path=None, github_user=None)

Download entire GitHub repo as a tar.gz archive, and extract it into specified path. :param repo: repo to download :param branch: branch to download :param account: GitHub account to download repo from :param path: path to extract to :param github_user: name of GitHub user to use

easybuild.tools.github.fetch_easyblocks_from_pr(pr, path=None, github_user=None)

Fetch patched easyconfig files for a particular PR.

easybuild.tools.github.fetch_easyconfigs_from_pr(pr, path=None, github_user=None)

Fetch patched easyconfig files for a particular PR.

easybuild.tools.github.fetch_files_from_pr(pr, path=None, github_user=None, github_account=None, github_repo=None)

Fetch patched files for a particular PR.

easybuild.tools.github.fetch_github_token(user)

Fetch GitHub token for specified user from keyring.

easybuild.tools.github.fetch_latest_commit_sha(repo, account, branch=None, github_user=None, token=None)

Fetch latest SHA1 for a specified repository and branch. :param repo: GitHub repository :param account: GitHub account :param branch: branch to fetch latest SHA1 for :param github_user: name of GitHub user to use :param token: GitHub token to use :return: latest SHA1

easybuild.tools.github.fetch_pr_data(pr, pr_target_account, pr_target_repo, github_user, full=False, **parameters)

Fetch PR data from GitHub

easybuild.tools.github.find_easybuild_easyconfig(github_user=None)

Fetches the latest EasyBuild version eb file from GitHub

Parameters:github_user – name of GitHub user to use when querying GitHub
easybuild.tools.github.find_software_name_for_patch(patch_name, ec_dirs)

Scan all easyconfigs in the robot path(s) to determine which software a patch file belongs to

Parameters:
  • patch_name – name of the patch file
  • ecs_dirs – list of directories to consider when looking for easyconfigs
Returns:

name of the software that this patch file belongs to (if found)

easybuild.tools.github.github_api_get_request(request_f, github_user=None, token=None, **kwargs)

Helper method, for performing get requests to GitHub API. :param request_f: function that should be called to compose request, providing a RestClient instance :param github_user: GitHub user name (to try and obtain matching GitHub token if none is provided) :param token: GitHub token to use :return: tuple with return status and data

easybuild.tools.github.github_api_put_request(request_f, github_user=None, token=None, **kwargs)

Helper method, for performing put requests to GitHub API. :param request_f: function that should be called to compose request, providing a RestClient instance :param github_user: GitHub user name (to try and obtain matching GitHub token if none is provided) :param token: GitHub token to use :return: tuple with return status and data

easybuild.tools.github.init_repo(path, repo_name, silent=False)

Initialize a new Git repository at the specified location.

Parameters:
  • path – location where Git repository should be initialized
  • repo_name – name of Git repository
  • silent – keep quiet (don’t print any messages)
easybuild.tools.github.is_patch_for(patch_name, ec)

Check whether specified patch matches any patch in the provided EasyConfig instance.

easybuild.tools.github.list_prs(params, per_page=100, github_user=None)

List pull requests according to specified selection/order parameters

Parameters:params – 3-tuple with selection parameters for PRs (<state>, <sort>, <direction>), see https://developer.github.com/v3/pulls/#parameters
easybuild.tools.github.merge_pr(pr)

Merge specified pull request

easybuild.tools.github.new_pr(paths, ecs, title=None, descr=None, commit_msg=None)

Open new pull request using specified files

Parameters:
  • paths – paths to categorized lists of files (easyconfigs, files to delete, patches)
  • ecs – list of parsed easyconfigs, incl. for dependencies (if robot is enabled)
  • title – title to use for pull request
  • descr – description to use for description
  • commit_msg – commit message to use
easybuild.tools.github.pick_default_branch(github_owner)

Determine default name to use.

easybuild.tools.github.post_comment_in_issue(issue, txt, account='easybuilders', repo='easybuild-easyconfigs', github_user=None)

Post a comment in the specified PR.

easybuild.tools.github.post_pr_labels(pr, labels)

Update PR labels

easybuild.tools.github.pr_files_cache(func)

Decorator to cache result of fetch_files_from_pr.

easybuild.tools.github.push_branch_to_github(git_repo, target_account, target_repo, branch)

Push specified branch to GitHub from specified git repository.

Parameters:
  • git_repo – git.Repo instance to use (after init_repo & setup_repo)
  • target_account – GitHub account name
  • target_repo – repository name
  • branch – name of branch to push
easybuild.tools.github.reasons_for_closing(pr_data)

Look for valid reasons to close PR by comparing with existing easyconfigs.

easybuild.tools.github.setup_repo(git_repo, target_account, target_repo, branch_name, silent=False, git_only=False)

Set up repository by checking out specified branch for specfied GitHub account/repository.

Parameters:
  • git_repo – git.Repo instance
  • target_account – name of GitHub account that owns GitHub repository
  • target_repo – name of GitHib repository
  • branch_name – name of branch to check out
  • silent – keep quiet (don’t print any messages)
  • git_only – only use git@github.com repo URL, skip trying https://github.com first
easybuild.tools.github.setup_repo_from(git_repo, github_url, target_account, branch_name, silent=False)

Set up repository by checking out specified branch from repository at specified URL.

Parameters:
  • git_repo – git.Repo instance
  • github_url – URL to GitHub repository
  • target_account – name of GitHub account that owns GitHub repository at specified URL
  • branch_name – name of branch to check out
  • silent – keep quiet (don’t print any messages)
easybuild.tools.github.sync_branch_with_develop(branch_name)

Sync branch with specified name with current develop branch.

easybuild.tools.github.sync_pr_with_develop(pr_id)

Sync pull request with specified ID with current develop branch.

easybuild.tools.github.sync_with_develop(git_repo, branch_name, github_account, github_repo)

Sync specified branch with develop branch.

easybuild.tools.github.validate_github_token(token, github_user)

Check GitHub token: * see if it conforms expectations (only [a-f]+[0-9] characters, length of 40) * see if it can be used for authenticated access