def build_release_notes(repository: Repository.Repository, tag: GitRef.GitRef) -> str: signature = ( "\n---\nReleased with [mozilla/task-boot](https://github.com/mozilla/task-boot)" ) # Get all commits between both versions using the comparison endpoint try: latest_release = repository.get_latest_release() diff = repository.compare(latest_release.tag_name, tag.ref) commits = diff.commits except UnknownObjectException: logger.info( "No previous release available, will use all commits on repo") commits = [commit for commit in repository.get_commits()] # List existing tags sha tags = [tag.commit.sha for tag in repository.get_tags()] # Use first line of every commit in between versions lines = [ "- {}".format(commit.commit.message.splitlines()[0]) for commit in commits if not is_release_commit(commit, tags) ] return "\n".join(lines) + signature
def __get_sha_for_tag(repository: Repository, tag: str) -> str: """ Gets necessary SHA value from selected repository's branch. """ branches = repository.get_branches() matched_branches = [match for match in branches if match.name == tag] if matched_branches: return matched_branches[0].commit.sha tags = repository.get_tags() matched_tags = [match for match in tags if match.name == tag] if not matched_tags: raise ValueError("No Tag or Branch exists with that name") return matched_tags[0].commit.sha
def get_version(github_repository: Repository) -> str: """ Return the next version. This is today’s date in the format ``YYYY.MM.DD.MICRO``. ``MICRO`` refers to the number of releases created on this date, starting from ``0``. """ utc_now = datetime.datetime.utcnow() date_format = '%Y.%m.%d' date_str = utc_now.strftime(date_format) tag_labels = [tag.name for tag in github_repository.get_tags()] today_tag_labels = [ item for item in tag_labels if item.startswith(date_str) ] micro = int(len(today_tag_labels)) new_version = f'{date_str}.{micro}' return new_version