@@ -17,6 +17,182 @@ as a helper in projects related to version control systems, versioning, and
1717automatic changelog generation. Applications in automation tools for validating
1818commit and pull request messages seem feasible as well.
1919
20+ ## Features
21+
22+ - Handle individual Gitmojis and their lists using Python classes. 👔
23+ - Fetch Gitmoji data directly from the official [ Gitmoji API] [ gitmoji-api ] . 😜
24+ - Graceful degradation: If the API is unavailable, fall back to backup data. 🛟
25+
26+ ## Installation
27+
28+ It is recommended to install the package directly from PyPI using ` pip ` :
29+
30+ ``` console
31+ $ pip install python-gitmojis
32+ ```
33+
34+ or any other dependency manager of your preference. After installation, the
35+ package functionalities can be accessed by importing them from the ` gitmojis `
36+ module:
37+
38+ ``` python
39+ import gitmojis
40+ ```
41+
42+ ## Usage
43+
44+ ### Data model
45+
46+ The data model incorporates two classes representing individual Gitmojis and
47+ their collections ("guides"), namely, ` Gitmoji ` and ` Guide ` , respectively.
48+
49+ The classes are defined in ` gitmojis.model ` , but can also be accessed directly
50+ from ` gitmojis ` as well:
51+
52+ ``` python
53+ from gitmojis import Gitmoji, Guide
54+ ```
55+
56+ #### ` gitmojis.model.Gitmoji `
57+
58+ The ` Gitmoji ` class is a Python ` @dataclass ` ([ PEP 557] [ PEP-557 ] ) that uses a
59+ set of fields consistent with the [ JSON schema] [ gitmoji-schema ] proposed in the
60+ original Gitmoji project, namely:
61+
62+ - ` emoji: str ` &ndash ; the emoji character representing the Gitmoji;
63+ - ` entity: str ` &ndash ; the HTML entity of the Gitmoji;
64+ - ` code: str ` &ndash ; the emoji's code to be used in rendering Gitmojis in the
65+ Markdown documents;
66+ - ` description: str ` &ndash ; a short note on the type of changes represented by
67+ the commits or pull requests marked by the Gitmoji;
68+ - ` name: str ` &ndash ; a text identifier of the Gitmoji;
69+ - ` semver: str | None ` &ndash ; the [ Semantic Versioning] ( https://semver.org )
70+ level affected by the changes marked with the Gitmoji; the allowed string
71+ values are ` "major" ` , ` "minor" ` , and ` "patch" ` .
72+
73+ The class can be used to create immutable objects representing individual
74+ Gitmojis, for example:
75+
76+ ``` python
77+ from gitmojis import Gitmoji
78+
79+ gitmoji = Gitmoji(
80+ emoji = " 🤖" ,
81+ entity = " 🤖" ,
82+ code = " :robot:" ,
83+ description = " Add or update Dependabot configuration." ,
84+ name = " robot" ,
85+ semver = None ,
86+ )
87+
88+ assert gitmoji.emoji == " 🤖"
89+ ```
90+
91+ > Note that when creating a new ` Gitmoji ` instance, all the ` @dataclass ` fields
92+ > are required. Furthermore, they all must be passed as keyword arguments.
93+
94+ #### ` gitmojis.model.Guide `
95+
96+ The ` Guide ` class aims to provide a custom list-like structure to manage a
97+ collection of Gitmojis. Its instances are created simply by passing an iterable
98+ of ` Gitmoji ` objects (as the ` gitmojis ` keyword argument) to the class
99+ constructor:
100+
101+ ``` python
102+ from gitmojis import Gitmoji, Guide
103+
104+ gitmojis_json = [
105+ {
106+ " emoji" : " 🤖" ,
107+ " entity" : " 🤖" ,
108+ " code" : " :robot:" ,
109+ " description" : " Add or update Dependabot configuration." ,
110+ " name" : " robot" ,
111+ " semver" : None ,
112+ },
113+ # ...
114+ ]
115+
116+ guide = Guide(
117+ gitmojis = [Gitmoji(** gitmoji_json) for gitmoji_json in gitmojis_json]
118+ )
119+
120+ assert guide[0 ].emoji == " 🤖"
121+ ```
122+
123+ The class is based on ` collections.UserList ` . Currently, it doesn't override
124+ any base class methods nor does it implement any custom functionality.
125+
126+ ### Fetching Gitmojis from the API
127+
128+ The main package functionality is implemented as a plain Python function, named
129+ ` fetch_guide ` . It can be imported either from ` gitmojis ` or directly from its
130+ source, i.e. the ` gitmojis.core ` module.
131+
132+ Usage of the function is extremely easy. In the simplest case, it can be called
133+ without any arguments:
134+
135+ ``` python
136+ from gitmojis import fetch_guide
137+
138+ guide = fetch_guide()
139+ ```
140+
141+ The function uses the ` requests ` library to return a ` Guide ` instance containing
142+ the current state of the official [ Gitmoji API] [ gitmoji-api ] . If the API is
143+ inaccessible, the guide can be populated using the data retrieved from the local
144+ backup file. Such behavior can be triggered by passing ` True ` as the value of
145+ the ` use_backup ` keyword argument (it defaults to ` False ` ):
146+
147+ ``` python
148+ from gitmojis import fetch_guide
149+
150+ guide = fetch_guide(use_backup = True ) # will work even if you're offline
151+ ```
152+
153+ ### Command-line interface (CLI)
154+
155+ The package comes with a simple CLI which can be run using the ` gitmojis `
156+ command:
157+
158+ ``` console
159+ $ gitmojis
160+ Usage: gitmojis [OPTIONS] COMMAND [ARGS]...
161+
162+ Command-line interface for managing the official Gitmoji guide.
163+
164+ Options:
165+ --use-backup Use the backup to fetch data if the API request fails.
166+ --version Show the version and exit.
167+ --help Show this message and exit.
168+
169+ Commands:
170+ sync Synchronize the backup file with the current state of the API.
171+ ```
172+
173+ As seen, currently the CLI provides only the ` sync ` command which can be used
174+ to update the Gitmoji data backup file to the current state of the official API
175+ endpoint.
176+
177+ > Checking for the updates of the API state is compared to the backup file by
178+ > executing the ` sync ` command at GitHub Actions runner every week. The
179+ > respective workflow automatically applies the updates and opens a pull
180+ > request introducing them to the codebase. We plan to do the version bump (on
181+ > a patch level) upon merging each of such pull requests. Therefore, to stay
182+ > tuned with the Gitmoji API backed up by this library, you should update
183+ > the package systematically. This particularly concerns the developers, who
184+ > work with local repositories most of the time.
185+
186+ ## Contributing
187+
188+ This project is open-source and embraces contributions of all types. For
189+ comprehensive instructions on how to contribute to the project, please refer to
190+ our [ Contributing Guide] [ contributing-guide ] .
191+
192+ We require all contributors to adhere to our [ Code of Conduct] [ code-of-conduct ] .
193+ While it may seem intricate at first glance, the essence is simple: treat
194+ everyone with kindness! 🙂
195+
20196## Credits
21197
22198The idea of Gitmoji was originally proposed, developed, and maintained by
@@ -33,14 +209,19 @@ Created by Kamil Paduszyński ([@paduszyk][github-paduszyk]).
33209Released under the [ MIT License] [ license ] .
34210
35211[ black ] : https://github.com/psf/black
212+ [ code-of-conduct ] : https://github.com/paduszyk/python-gitmojis/blob/main/.github/CODE_OF_CONDUCT.md
36213[ codecov ] : https://app.codecov.io/gh/paduszyk/python-gitmojis
214+ [ contributing-guide ] : https://github.com/paduszyk/python-gitmojis/blob/main/.github/CONTRIBUTING.md
37215[ github-build-workflow ] : https://github.com/paduszyk/python-gitmojis/actions/workflows/build-package.yml
38216[ github-carlosquesta ] : https://github.com/carloscuesta
39217[ github-paduszyk ] : https://github.com/paduszyk
218+ [ gitmoji-api ] : https://github.com/carloscuesta/gitmoji/tree/master/packages/gitmojis#api
40219[ gitmoji-repository ] : https://github.com/carloscuesta/gitmoji
220+ [ gitmoji-schema ] : https://github.com/carloscuesta/gitmoji/blob/master/packages/gitmojis/src/schema.json
41221[ gitmoji-website ] : https://gitmoji.dev
42222[ license ] : https://github.com/paduszyk/python-gitmojis/blob/main/LICENSE
43223[ mypy ] : https://github.com/python/mypy
44224[ nox ] : https://github.com/wntrblm/nox
225+ [ pep-557 ] : https://peps.python.org/pep-0557/
45226[ pre-commit.ci ] : https://results.pre-commit.ci/latest/github/paduszyk/python-gitmojis/main
46227[ ruff ] : https://github.com/astral-sh/ruff
0 commit comments