1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
{% from 'macros.common.j2' import capitalize_first_letter_only %}
{#
MACRO: format a post-paragraph link reference in RST
#}{% macro format_link_reference(link, label)
%}{{ ".. _%s: %s" | format(label, link)
}}{% endmacro
%}
{# MACRO: generate a heading underline that matches the exact length of the header #}
{% macro generate_heading_underline(header, underline_char)
%}{% set header_underline = []
%}{% for _ in header
%}{% set __ = header_underline.append(underline_char)
%}{% endfor
%}{# # Print out the header underline
#}{{ header_underline | join
}}{% endmacro
%}
{#
MACRO: formats a commit message for a non-inline RST link for a commit hash and/or PR/MR
#}{% macro commit_msg_links(commit)
%}{% if commit.error is undefined
%}{#
# # Initialize variables
#}{% set closes_statement = ""
%}{% set link_references = []
%}{% set summary_line = capitalize_first_letter_only(
commit.descriptions[0] | safe
)
%}{#
#}{% if commit.linked_issues | length > 0
%}{% set closes_statement = ", closes `%s`_" | format(
commit.linked_issues | join("`_, `")
)
%}{% endif
%}{#
#}{% if commit.linked_merge_request != ""
%}{# # Add PR references with a link to the PR
#}{% set _ = link_references.append("`PR%s`_" | format(commit.linked_merge_request))
%}{% endif
%}{#
# DEFAULT: Always include the commit hash as a link
#}{% set _ = link_references.append("`%s`_" | format(commit.short_hash))
%}{#
#}{% set formatted_links = ""
%}{% if link_references | length > 0
%}{% set formatted_links = " (%s)" | format(link_references | join(", "))
%}{% endif
%}{#
# Return the modified summary_line
#}{{ summary_line ~ closes_statement ~ formatted_links
}}{% endif
%}{% endmacro
%}
{#
MACRO: format commit summary line
#}{% macro format_commit_summary_line(commit)
%}{# # Check for Parsing Error
#}{% if commit.error is undefined
%}{#
# # Add any message links to the commit summary line
#}{% set summary_line = commit_msg_links(commit)
%}{#
#}{% if commit.scope
%}{% set summary_line = "**%s**: %s" | format(commit.scope, summary_line)
%}{% endif
%}{#
# # Return the modified summary_line
#}{{ summary_line
}}{#
#}{% else
%}{# # Return the first line of the commit if there was a Parsing Error
#}{{ (commit.commit.message | string).split("\n", maxsplit=1)[0]
}}{% endif
%}{% endmacro
%}
{#
MACRO: Extract issue references from a parsed commit object
- Stores the issue urls in the namespace object
#}{% macro extract_issue_link_references(ns, commit)
%}{% set issue_urls = []
%}{#
#}{% if commit.linked_issues is defined and commit.linked_issues | length > 0
%}{% for issue_num in commit.linked_issues
%}{# # Create an issue reference url
#}{% set _ = issue_urls.append(
format_link_reference(
issue_num | issue_url,
issue_num,
)
)
%}{% endfor
%}{% endif
%}{#
# # Store the issue urls in the namespace object
#}{% set ns.urls = issue_urls
%}{% endmacro
%}
{#
MACRO: Create & return an non-inline RST link from a commit message
- Returns empty string if no PR/MR identifier is found
#}{% macro extract_pr_link_reference(commit)
%}{% if commit.error is undefined
%}{% set summary_line = commit.descriptions[0]
%}{#
#}{% if commit.linked_merge_request != ""
%}{# # Create a PR/MR reference url
#}{{ format_link_reference(
commit.linked_merge_request | pull_request_url,
"PR" ~ commit.linked_merge_request,
)
}}{% endif
%}{% endif
%}{% endmacro
%}
|