Skip to content

Commit 8685aa9

Browse files
authored
Merge pull request #163 from sommersoft/ci_no_release
Ignore Local/CI Changes When Flagging A Required Release
2 parents 827d76f + 8df498e commit 8685aa9

File tree

1 file changed

+48
-22
lines changed

1 file changed

+48
-22
lines changed

adabot/lib/circuitpython_library_validators.py

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,28 @@ def validate_repo_state(self, repo):
232232

233233
def validate_release_state(self, repo):
234234
"""Validate if a repo 1) has a release, and 2) if there have been commits
235-
since the last release.
235+
since the last release. Only files that drive user-facing changes
236+
will be considered when flagging a repo as needing a release.
236237
237238
If 2), categorize by length of time passed since oldest commit after the release,
238239
and return the number of days that have passed since the oldest commit.
239240
"""
241+
242+
def _filter_file_diffs(filenames):
243+
_ignored_files = {
244+
"CODE_OF_CONDUCT.md",
245+
"LICENSE",
246+
"setup.py.disabled",
247+
}
248+
compare_files = [
249+
name for name in filenames if not name.startswith(".")
250+
]
251+
non_ignored_files = list(
252+
set(compare_files).difference(_ignored_files)
253+
)
254+
255+
return non_ignored_files
256+
240257
if not (repo["owner"]["login"] == "adafruit" and
241258
repo["name"].startswith("Adafruit_CircuitPython")):
242259
return []
@@ -281,28 +298,37 @@ def validate_release_state(self, repo):
281298
return [ERROR_OUTPUT_HANDLER]
282299
compare_tags_json = compare_tags.json()
283300
if "status" in compare_tags_json:
284-
if compare_tags.json()["status"] != "identical":
285-
oldest_commit_date = datetime.datetime.today()
286-
for commit in compare_tags_json["commits"]:
287-
commit_date = datetime.datetime.strptime(commit["commit"]["committer"]["date"], "%Y-%m-%dT%H:%M:%SZ")
288-
if commit_date < oldest_commit_date:
289-
oldest_commit_date = commit_date
290-
291-
date_diff = datetime.datetime.today() - oldest_commit_date
292-
#print("{0} Release State:\n Tag Name: {1}\tRelease Date: {2}\n Today: {3}\t Released {4} days ago.".format(repo["name"], tag_name, oldest_commit_date, datetime.datetime.today(), date_diff.days))
293-
#print("Compare {4} status: {0} \n Ahead: {1} \t Behind: {2} \t Commits: {3}".format(
294-
# compare_tags_json["status"], compare_tags_json["ahead_by"],
295-
# compare_tags_json["behind_by"], compare_tags_json["total_commits"], repo["full_name"]))
296-
if date_diff.days > datetime.date.today().max.day:
297-
return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_GTM,
298-
date_diff.days)]
299-
elif date_diff.days <= datetime.date.today().max.day:
300-
if date_diff.days > 7:
301-
return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_1M,
302-
date_diff.days)]
303-
else:
304-
return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_1W,
301+
if compare_tags_json["status"] != "identical":
302+
303+
comp_filenames = [
304+
file["filename"] for file in compare_tags_json.get("files")
305+
]
306+
filtered_files = _filter_file_diffs(comp_filenames)
307+
308+
if filtered_files:
309+
oldest_commit_date = datetime.datetime.today()
310+
for commit in compare_tags_json["commits"]:
311+
commit_date_val = commit["commit"]["committer"]["date"]
312+
commit_date = datetime.datetime.strptime(commit_date_val,
313+
"%Y-%m-%dT%H:%M:%SZ")
314+
if commit_date < oldest_commit_date:
315+
oldest_commit_date = commit_date
316+
317+
date_diff = datetime.datetime.today() - oldest_commit_date
318+
#print("{0} Release State:\n Tag Name: {1}\tRelease Date: {2}\n Today: {3}\t Released {4} days ago.".format(repo["name"], tag_name, oldest_commit_date, datetime.datetime.today(), date_diff.days))
319+
#print("Compare {4} status: {0} \n Ahead: {1} \t Behind: {2} \t Commits: {3}".format(
320+
# compare_tags_json["status"], compare_tags_json["ahead_by"],
321+
# compare_tags_json["behind_by"], compare_tags_json["total_commits"], repo["full_name"]))
322+
if date_diff.days > datetime.date.today().max.day:
323+
return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_GTM,
305324
date_diff.days)]
325+
elif date_diff.days <= datetime.date.today().max.day:
326+
if date_diff.days > 7:
327+
return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_1M,
328+
date_diff.days)]
329+
else:
330+
return [(ERROR_GITHUB_COMMITS_SINCE_LAST_RELEASE_1W,
331+
date_diff.days)]
306332
elif "errors" in compare_tags_json:
307333
# replace 'output_handler' with ERROR_OUTPUT_HANDLER
308334
err_msg = [

0 commit comments

Comments
 (0)