mirror of
https://github.com/suitenumerique/meet.git
synced 2026-09-01 05:07:56 +00:00
a0dbfa9357
The rule downloaded the gitmoji list with requests, so lint-git had to install that package before the linter could run. urllib.request is in the standard library and answers the same call, leaving one fewer package fetched on the runner before the job's own command starts.
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""
|
|
Gitlint extra rule to validate that the message title is of the form
|
|
"<gitmoji>(<scope>) <subject>"
|
|
"""
|
|
|
|
import json
|
|
import re
|
|
import urllib.request
|
|
|
|
from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation
|
|
|
|
GITMOJIS_URL = "https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json"
|
|
|
|
|
|
class GitmojiTitle(LineRule):
|
|
"""
|
|
This rule will enforce that each commit title is of the form "<gitmoji>(<scope>) <subject>"
|
|
where gitmoji is an emoji from the list defined in https://gitmoji.carloscuesta.me and
|
|
subject should be all lowercase
|
|
"""
|
|
|
|
id = "UC1"
|
|
name = "title-should-have-gitmoji-and-scope"
|
|
target = CommitMessageTitle
|
|
|
|
def validate(self, title, _commit):
|
|
"""
|
|
Download the list possible gitmojis from the project's github repository and check that
|
|
title contains one of them.
|
|
"""
|
|
with urllib.request.urlopen(GITMOJIS_URL, timeout=10) as response:
|
|
gitmojis = json.load(response)["gitmojis"]
|
|
emojis = [item["emoji"] for item in gitmojis]
|
|
pattern = r"^({:s})\(.*\)\s[a-z].*$".format("|".join(emojis))
|
|
if not re.search(pattern, title):
|
|
violation_msg = 'Title does not match regex "<gitmoji>(<scope>) <subject>"'
|
|
return [RuleViolation(self.id, violation_msg, title)]
|