def _create_fix(self, reposlug: str, repo: Repository, branch: str,
                 result: ScanResult) -> None:
     new_content = "{}\n{}\n".format(result.content,
                                     "\n".join(result.missings))
     repo.update_file(result.filename,
                      message="Autofix by devsecops",
                      content=new_content,
                      sha=result.filesha,
                      branch=branch)
     print("[I] Updated {}: {}".format(reposlug, result.filename))
Example #2
0
def update_changelog(version: str, github_repository: Repository) -> None:
    """
    Add a version title to the changelog.
    """
    changelog_path = Path('CHANGELOG.rst')
    branch = 'master'
    changelog_content_file = github_repository.get_contents(
        path=str(changelog_path),
        ref=branch,
    )
    changelog_bytes = changelog_content_file.decoded_content
    changelog_contents = changelog_bytes.decode('utf-8')
    new_changelog_contents = changelog_contents.replace(
        'Next\n----',
        f'Next\n----\n\n{version}\n------------',
    )
    github_repository.update_file(
        path=str(changelog_path),
        message=f'Update for release {version}',
        content=new_changelog_contents,
        sha=changelog_content_file.sha,
    )