Skip to content

Commit 5f67e79

Browse files
authored
Fix assert news bug (#16)
1 parent f6b7f24 commit 5f67e79

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

continuous_delivery_scripts/assert_news.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ def validate_news_files(git: GitWrapper, root_dir: str, news_dir: str) -> None:
9393
validate_news_file(absolute_file_path)
9494

9595

96-
def generate_news_file(git: GitWrapper, news_dir: str) -> pathlib.Path:
96+
def generate_news_file(git: GitWrapper, news_dir: pathlib.Path) -> pathlib.Path:
9797
"""Adds a news file if the branch corresponds to an dependency update.
9898
9999
Args:
100100
git: Instance of GitWrapper.
101-
news_dir: Relative path to news directory.
101+
news_dir: path to news directory.
102102
"""
103103
current_branch = str(git.get_current_branch())
104104
is_dependency_update, groups = git.is_current_branch_of_type(
@@ -114,19 +114,21 @@ def generate_news_file(git: GitWrapper, news_dir: str) -> pathlib.Path:
114114
)
115115
logger.info(f"Generating a news file with content: {message}...")
116116
return create_news_file(
117-
news_dir,
117+
str(news_dir),
118118
message,
119119
configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_TYPE),
120120
)
121121

122122

123-
def _commit_news_file(git: GitWrapper, news_file: pathlib.Path) -> None:
123+
def _commit_news_file(git: GitWrapper, news_file: pathlib.Path, local: bool) -> None:
124124
logger.info(f"Committing news file {str(news_file)}...")
125-
git.configure_for_github()
125+
if not local:
126+
git.configure_for_github()
126127
git.add(str(news_file))
127128
git.commit("📰 Automatic changes ⚙ Adding news file")
128-
git.push()
129-
git.pull()
129+
if not local:
130+
git.push()
131+
git.pull()
130132

131133

132134
def main() -> None:
@@ -152,8 +154,8 @@ def main() -> None:
152154
except Exception as e:
153155
log_exception(logger, e)
154156
try:
155-
news_file = generate_news_file(git, absolute_news_dir)
156-
_commit_news_file(git, news_file)
157+
news_file = generate_news_file(git, git.get_corresponding_path(pathlib.Path(news_dir)))
158+
_commit_news_file(git, news_file, args.local)
157159
except Exception as e2:
158160
log_exception(logger, e2)
159161
sys.exit(1)

continuous_delivery_scripts/utils/git_helpers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,23 @@ def apply_uncommitted_changes(self, other_repo: "GitWrapper") -> None:
606606
else:
607607
GitWrapper._apply_deletions(destination)
608608

609+
def get_corresponding_path(self, path_in_initial_repo: Path) -> Path:
610+
"""Gets the path in current repository corresponding to path in initial repository.
611+
612+
If current repository is not a clone, then identical absolute path is returned.
613+
614+
Args:
615+
path_in_initial_repo: path to a file/directory in initial repository.
616+
617+
Returns:
618+
corresponding path.
619+
"""
620+
return (
621+
path_in_initial_repo
622+
if path_in_initial_repo.is_absolute()
623+
else Path(self.root).joinpath(path_in_initial_repo)
624+
)
625+
609626

610627
class ProjectGitWrapper(GitWrapper):
611628
"""Wrapper class over project's repository."""

news/202108110247.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed dependency update news file bug

news/20210811024701.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed local assert news file

0 commit comments

Comments
 (0)