Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

conventional_commit_regex.py 2.3 KB

You have to be logged in to leave a comment. Sign In
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
  1. import re
  2. from typing import Optional
  3. from bohrapi.artifacts import Commit
  4. from bohrapi.core import Heuristic
  5. from bohrlabels.core import OneOrManyLabels
  6. from bohrlabels.labels import CommitLabel
  7. example1 = """feat: allow provided config object to extend other configs
  8. BREAKING CHANGE: `extends` key in config file is now used for extending other config files
  9. """
  10. example2 = """refactor!: drop support for Node 6
  11. """
  12. example3 = """refactor!: drop support for Node 6
  13. BREAKING CHANGE: refactor to use JavaScript features not available in Node 6.
  14. """
  15. example4 = """docs: correct spelling of CHANGELOG
  16. """
  17. example5 = """feat(lang): add polish language
  18. """
  19. example6 = """fix: correct minor typos in code
  20. see the issue for details
  21. on typos fixed.
  22. Reviewed-by: Z
  23. Refs #133
  24. """
  25. REGEX = re.compile(
  26. r"\A(((Initial commit)|(Merge [^\r\n]+)|"
  27. r"((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(\w+\))?!?: [^\r\n]+"
  28. r"((\r|\n|\r\n)((\r|\n|\r\n)[^\r\n]+)+)*"
  29. r")"
  30. r")(\r|\n|\r\n)?)"
  31. )
  32. @Heuristic(Commit)
  33. def conventional_commit_regex(commit: Commit) -> Optional[OneOrManyLabels]:
  34. """
  35. >>> conventional_commit_regex(Commit({"author": 'a', "repository": 'a', "_id": '1df23', "message": example1}))
  36. CommitLabel.Feature
  37. >>> conventional_commit_regex(Commit({"author": 'a', "repository": 'a', "_id": '1df23', "message": example2}))
  38. CommitLabel.Refactoring
  39. >>> conventional_commit_regex(Commit({"author": 'a', "repository": 'a', "_id": '1df23', "message": example3}))
  40. CommitLabel.Refactoring
  41. >>> conventional_commit_regex(Commit({"author": 'a', "repository": 'a', "_id": '1df23', "message": example4}))
  42. CommitLabel.DocChange
  43. >>> conventional_commit_regex(Commit({"author": 'a', "repository": 'a', "_id": '1df23', "message": example5}))
  44. CommitLabel.Feature
  45. >>> conventional_commit_regex(Commit({"author": 'a', "repository": 'a', "_id": '1df23', "message": example6}))
  46. CommitLabel.BugFix
  47. """
  48. m = REGEX.match(commit.message.raw)
  49. if m is None:
  50. return None
  51. type = m.groups()[5]
  52. if type == "fix":
  53. return CommitLabel.BugFix
  54. elif type == "feat":
  55. return CommitLabel.Feature
  56. elif type == "refactor":
  57. return CommitLabel.Refactoring
  58. elif type == "docs":
  59. return CommitLabel.DocChange
  60. else:
  61. return None
  62. # TODO add more types
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...