compliance.utils.services package

Submodules

compliance.utils.services.github module

Compliance Github service helper.

class compliance.utils.services.github.Github(config=None, base_url='https://github.com')[source]

Bases: object

Github service helper class.

add_card(column_id, message=None, issue=0)[source]

Create a card in a project column.

add_issue(owner, repo, title, body='', annotation=None, **kwargs)[source]

Create a repository issue.

add_issue_comment(owner, repo, issue, body, annotation=None)[source]

Create a comment for a repository issue.

add_milestone(owner, repo, milestone)[source]

Create a repository milestone.

apply_labels(repo, issue, *labels)[source]

Add label(s) to an issue.

repo looks like: my-gh-org/my-gh-repo issue is an issue number (not id) API takes a json list of labels POST /repos/:owner/:repo/issues/:number/labels

create_column(project_id, column, org=False)[source]

Create a project column.

create_label(repo, name, org=False)[source]

Create a label within a repository.

create_project(repo, name, body='', org=False)[source]

Create a repository project.

creates_for_project(url, data, org=False)[source]

Create a repository project based on a properly formed url.

extract_owner_repo(url)[source]

Retrieve the owner (org) and repo from the url.

extract_owner_repo_issue(url)[source]

Retrieve the owner (org), repo and issue number from the url.

extract_path_chunks(url)[source]

Retrieve the path from the url.

get_all_cards(columns)[source]

Retrieve all cards for a given list of project columns.

get_all_issues(owner, repo, **kwargs)[source]

Retrieve all issues for a repository.

get_all_projects(repo_path)[source]

Retrieve all GH repo projects.

repo_path looks like: my-gh-org/my-gh-repo

get_branch_protection_details(repo, branch='master')[source]

Retrieve a repository branch’s branch protection details.

Parameters:
  • repo – the organization/repository as a string.

  • branch – the branch as a string.

Returns:

the repository branch’s branch protection details.

get_cards(column_id)[source]

Retrieve all cards for a given project column.

get_columns(project_id)[source]

Retrieve the columns for a project.

get_commit_details(repo, since, branch='master', path=None)[source]

Retrieve a repository branch’s commit details since a given date/time.

Parameters:
  • repo – the organization/repository as a string.

  • since – the starting date/time as a datetime.

  • branch – the branch as a string. Defaults to master.

  • path – if provided, only commits for the path will be returned.

Returns:

the repo branch’s commit details since a given date/time.

get_issue(owner, repo, issue, parse_annotations=False)[source]

Retrieve the content and metadata for a repository issue.

If parse_annotations is True, then returns (issue, body, annotations), where body is the body with the JSON annotations removed, and annotations is a dictionary of the annotations. The annotations will be an empty dictionary if there aren’t any.

get_issue_comments(owner, repo, issue, parse_annotations=False)[source]

Retrieve a repository issue’s comments.

get_issues_page(owner, repo, **kwargs)[source]

Retrieve a repository’s issues by page.

get_project(project, org=False)[source]

Retrieve the GH org or org/repo project.

For a repo project the project variable looks like:

my-gh-org/my-gh-repo/projects/1

For an org project the project variable looks like:

my-gh-org/projects/1

get_pull_requests(repo, since=None, **kwargs)[source]

Retrieve a repository’s pull request information.

Parameters:
  • repo – the organization/repository as a string.

  • since – the starting date/time of a pull request as a datetime.

  • kwargs – key/value pairs of GH pulls API accepted params

Returns:

Repository pull request metadata

get_repo_details(repo)[source]

Retrieve a repository’s metadata.

Parameters:

repo – the organization/repository as a string.

Returns:

the repository’s metadata details.

list_milestones(owner, repo, state='open', sort='due_on', direction='asc')[source]

Retrieve a repository’s milestones.

make_request(method, url, parse=True, **kwargs)[source]

Perform a REST call to the Github API.

Parameters:
  • method – HTTP request method

  • url – The URL to make the request to

  • parse – Return the JSON response content, defaults to True. If False then the entire response is returned

  • kwargs – Additional arguments added directly to the request call

Returns:

response content from the request made

move_card(card, to_column_id)[source]

Move a card from one project column to another.

paginate_api(api_url, **kwargs)[source]

Perform GET calls handling pagination.

Parameters:
  • api_url – The URL to make the GET request to

  • kwargs – Additional arguments added directly to the request call

Returns:

Combined paginated JSON content

patch_issue(owner, repo, issue, annotation=None, **params)[source]

Edit a repository issue.

rand_color()[source]

Generate a random color for labels.

remove_labels(repo, issue, *labels)[source]

Remove label(s) from an issue.

repo looks like: my-gh-org/my-gh-repo issue is an issue number (not id) API takes a json list of labels POST /repos/:owner/:repo/issues/:number/labels

search_issues(query, sort=None, order=None, owner=None, repo=None)[source]

Perform a search against all issues based on the query provided.

If an owner and repo are passed in, then restrict the results to that repo. Note that this can also be done in the query directly.

update_annotations(owner, repo, issue, annotations)[source]

Update the body of an existing issue, only changing the annotations.

If there are no existing annotations, the annotation block will be added. If there is existing annotations, the given annotations will be merged into them.

compliance.utils.services.github.extract_annotations(content)[source]

Retrieve JSON annotations from a string (issue body).

Returns the remaining content without the annotations, and then the annotations themselves as a dictionary.

compliance.utils.services.pagerduty module

Compliance Pagerduty service helper.

compliance.utils.services.pagerduty.delete(path, params=None, headers=None, creds=None)[source]

Perform a DELETE operation.

Returns the result as requests.Response object. This uses the PD API v2.

Parameters:
  • path – API endpoint to call (e.g. ‘users’)

  • params – a dictionary with parameters

  • headers – a dictionary with headers to include

  • creds – a Config object with PagerDuty credentials

compliance.utils.services.pagerduty.get(path, params=None, headers=None, creds=None)[source]

Perform a GET operation.

Returns the pages wrapped as requests.Response object. This uses the PD API v2.

Parameters:
  • path – API endpoint to call (e.g. ‘users’)

  • params – a dictionary with parameters

  • headers – a dictionary with headers to include

  • creds – a Config object with PagerDuty credentials

compliance.utils.services.pagerduty.post(path, params=None, headers=None, creds=None)[source]

Perform a POST operation.

Returns the result as requests.Response objects. This uses the PD API v2.

Parameters:
  • path – API endpoint to call (e.g. ‘users’)

  • params – a dictionary with parameters

  • headers – a dictionary with headers to include

  • creds – a Config object with PagerDuty credentials

compliance.utils.services.pagerduty.put(path, params=None, headers=None, creds=None)[source]

Perform a PUT operation.

Return the result as requests.Response object. This uses the PD API v2.

Parameters:
  • path – API endpoint to call (e.g. ‘users’)

  • params – a dictionary with parameters

  • headers – a dictionary with headers to include

  • creds – a Config object with PagerDuty credentials

compliance.utils.services.pagerduty.send_event(action, check, title, source, severity='error', details='', links=None, creds=None)[source]

Send an event to PD using the Events API.

Module contents

Compliance automation utilities services package.