Skip to content

Commit

Permalink
Allow DoD criteria to be optional
Browse files Browse the repository at this point in the history
Satisfies #39 and an extra request in #38
  • Loading branch information
platisd committed Feb 22, 2024
1 parent 4d24f14 commit e69d712
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ with the syntax described earlier.
most importantly edit your pull request description.
* (Optional) `message_header`: You may provide a custom message to be displayed above the checklist instead of the
default one found in [action.yml](action.yml).
* (Optional) `optional_tag`: A tag that if found in a DoD checklist item in its beginning or end, will denote that
the specific item is optional. The tag will **not** be removed from the item, but it will be ignored when checking
if the DoD is satisfied.
* Example: `optional_tag: "[OPTIONAL]"` will make the action ignore items like `"[OPTIONAL] Checklist item 1"`.

### Using multiple DoD checklists

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
message_header:
description: 'The header of the message with the DoD checklist'
default: '### :ballot_box_with_check: Definition of Done checklist'
optional_tag:
description: 'The tag to use for optional items in the beginning or the end of a criterion'
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
33 changes: 29 additions & 4 deletions run_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def assert_config(config: dict):
assert isinstance(config["dod"], list), "DoD section is not a list"


def has_unsatisfied_dod(pull_request_description, dod_criteria):
def has_unsatisfied_dod(pull_request_description, dod_criteria, optional_tag):
# Extract the bot message from the pull request description
bot_message_begin = pull_request_description.find(MESSAGE_HEADER)
last_criterion = dod_criteria[-1].replace(RIGHT_ARROW_EMOJI, "")
Expand All @@ -103,9 +103,33 @@ def has_unsatisfied_dod(pull_request_description, dod_criteria):
+ "Please fully remove any remnants of the bot's comment and try again."
)
return True
bot_message = pull_request_description[bot_message_begin:bot_message_end]
bot_message = pull_request_description[
bot_message_begin : bot_message_end + len(last_criterion)
]

return EMPTY_CHECKMARK in bot_message
# If all boxes are checked, then the DoD is satisfied
if EMPTY_CHECKMARK not in bot_message:
print("All DoD criteria are satisfied, no unchecked boxes")
return False
# If there are unchecked boxes and no optional tags, then the DoD is unsatisfied
if not optional_tag:
print("There are unchecked DoD criteria and no optional tags")
return True

print("There are unchecked DoD criteria but they might be optional")
# If there are optional tags, then only unchecked boxes WITHOUT the optional tag
# are unsatisfied criteria
for line in bot_message.split("\n"):
line = line.strip()
if line.startswith(EMPTY_CHECKMARK):
criterion = line[len(EMPTY_CHECKMARK) :].strip()
if criterion.startswith(optional_tag) or criterion.endswith(optional_tag):
continue # Ignore the optional unchecked criterion
print("Found unchecked DoD criteria that are not optional")
return True # Found an unsatisfied non-optional criterion

print("Found unchecked DoD criteria, but all of them were optional")
return False


def main():
Expand Down Expand Up @@ -157,7 +181,8 @@ def main():

maybe_replace_config(config, pull_request_description)
if has_bot_comment(pull_request_description):
if has_unsatisfied_dod(pull_request_description, config["dod"]):
optional_tag = os.environ.get("INPUT_OPTIONAL_TAG")
if has_unsatisfied_dod(pull_request_description, config["dod"], optional_tag):
print(
"The Definition of Done for this pull request "
+ "has not been yet been fully marked as satisfied "
Expand Down

0 comments on commit e69d712

Please sign in to comment.