Skip to content

Commit d841d76

Browse files
committed
action: Generalize new revision check
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
1 parent b884704 commit d841d76

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

action.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def is_sha(rev):
127127

128128
return len(rev) == 40
129129

130-
def is_impostor(repo, rev):
130+
def is_valid_rev(repo, rev, check_impostor):
131131

132132
def compare(base, head):
133133
try:
@@ -138,32 +138,29 @@ def compare(base, head):
138138
log(f"No common ancestor between {base} and {head}")
139139
return False
140140
else:
141-
log(f'compare: GithubException: {e}')
141+
log(f'check_rev: compare: GithubException: {e}')
142142
raise
143-
return c.status in ('behind', 'identical')
143+
status_ok = ('behind', 'identical') if is_sha(head) else ('identical')
144+
return c.status in status_ok
144145

145146
if not rev:
146-
log('is_impostor: revision is None')
147-
return True
148-
149-
if not is_sha(rev):
150-
log('is_impostor: not a SHA')
147+
log('check_rev: rev is None')
151148
return False
152149

153150
try:
154151
for b in repo.get_branches():
155152
if compare(f'refs/heads/{b.name}', rev):
156-
log(f'Found revision {rev} in branch {b.name}')
157-
return False
153+
log(f'check_rev: Found revision {rev} in branch {b.name}')
154+
return True
158155
for t in repo.get_tags():
159156
if compare(f'refs/tags/{t.name}', rev):
160-
log(f'Found revision {rev} in tag {t.name}')
161-
return False
157+
log(f'check_rev: Found revision {rev} in tag {t.name}')
158+
return True
162159
except GithubException as e:
163-
log(f'is_impostor: GithubException: {e}')
164-
return True
160+
log(f'check_rev: GithubException: {e}')
161+
return False
165162

166-
return True
163+
return False
167164

168165
def fmt_rev(repo, rev):
169166
if not rev:

0 commit comments

Comments
 (0)