Skip to content
Snippets Groups Projects
Commit e95e1161 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Automatically detect changes in bob.devtools

parent 4f5d702c
No related branches found
No related tags found
1 merge request!145Improve the release scripts
Pipeline #37481 passed
...@@ -43,7 +43,7 @@ def _sort_tags(tags, reverse): ...@@ -43,7 +43,7 @@ def _sort_tags(tags, reverse):
def get_file_from_gitlab(gitpkg, path, ref="master"): def get_file_from_gitlab(gitpkg, path, ref="master"):
"""Retrieves a file from a Gitlab repository, returns a (StringIO) file.""" """Retrieves a file from a Gitlab repository, returns a (StringIO) file."""
return io.StringIO(gitpkg.files.get(file_path=path, ref=branch).decode()) return io.StringIO(gitpkg.files.get(file_path=path, ref=ref).decode())
def get_last_tag(package): def get_last_tag(package):
...@@ -229,18 +229,21 @@ def _write_mergerequests_range(f, pkg_name, mrs): ...@@ -229,18 +229,21 @@ def _write_mergerequests_range(f, pkg_name, mrs):
f.write("\n") f.write("\n")
def write_tags_with_commits(f, gitpkg, since, mode): def get_changes_since(gitpkg, since):
"""Writes all tags and commits of a given package to the output file. """Gets the list of MRs, tags, and commits since the provided date
Args: Parameters
----------
gitpkg : object
A gitlab pakcage object
since : object
A parsed date
f: A :py:class:`File` ready to be written at Returns
gitpkg: A pointer to the gitlab package object -------
since: Starting date (as a datetime object) tuple
mode: One of mrs (merge-requests), commits or tags indicating how to mrs, tags, commits
list entries in the changelog for this package
""" """
# get tags since release and sort them # get tags since release and sort them
tags = gitpkg.tags.list() tags = gitpkg.tags.list()
...@@ -265,6 +268,21 @@ def write_tags_with_commits(f, gitpkg, since, mode): ...@@ -265,6 +268,21 @@ def write_tags_with_commits(f, gitpkg, since, mode):
) )
) )
) )
return mrs, tags, commits
def write_tags_with_commits(f, gitpkg, since, mode):
"""Writes all tags and commits of a given package to the output file.
Args:
f: A :py:class:`File` ready to be written at
gitpkg: A pointer to the gitlab package object
since: Starting date (as a datetime object)
mode: One of mrs (merge-requests), commits or tags indicating how to
list entries in the changelog for this package
"""
mrs, tags, commits = get_changes_since(gitpkg, since)
f.write("* %s\n" % (gitpkg.attributes["path_with_namespace"],)) f.write("* %s\n" % (gitpkg.attributes["path_with_namespace"],))
# go through tags and writes each with its message and corresponding # go through tags and writes each with its message and corresponding
......
#!/usr/bin/env python #!/usr/bin/env python
import os
import sys
import datetime
import click import click
from . import bdt from . import bdt
from ..changelog import get_last_tag_date, write_tags_with_commits
from ..changelog import parse_date
from ..release import get_gitlab_instance
from ..log import verbosity_option, get_logger from ..log import verbosity_option, get_logger
logger = get_logger(__name__) logger = get_logger(__name__)
...@@ -104,6 +96,18 @@ def changelog(target, changelog, group, mode, since): ...@@ -104,6 +96,18 @@ def changelog(target, changelog, group, mode, since):
starting date is not passed, we'll use the date of the last tagged value or starting date is not passed, we'll use the date of the last tagged value or
the date of the first commit, if no tags are available in the package. the date of the first commit, if no tags are available in the package.
""" """
import os
import sys
import datetime
from ..changelog import (
get_last_tag_date,
write_tags_with_commits,
parse_date,
get_changes_since,
get_last_tag,
)
from ..release import get_gitlab_instance
gl = get_gitlab_instance() gl = get_gitlab_instance()
...@@ -125,8 +129,16 @@ def changelog(target, changelog, group, mode, since): ...@@ -125,8 +129,16 @@ def changelog(target, changelog, group, mode, since):
since = parse_date(since) since = parse_date(since)
# Since tagging packages requires bob.devtools to be tagged first. Add that to the # Since tagging packages requires bob.devtools to be tagged first. Add that to the
# list as well. Note that bob.devtools can release itself. # list as well if bob.devtools has changed. Note that bob.devtools can release
if len(packages) > 1: # itself.
def bdt_has_changes():
gitpkg = gl.projects.get("bob/bob.devtools")
tag = get_last_tag(gitpkg)
last_tag_date = parse_date(tag.commit["committed_date"])
_, _, commits = get_changes_since(gitpkg, last_tag_date)
return len(commits)
if bdt_has_changes():
packages.insert(0, "bob/bob.devtools") packages.insert(0, "bob/bob.devtools")
# iterates over the packages and dumps required information # iterates over the packages and dumps required information
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment