Skip to content

Commit b45bf4e

Browse files
committed
add more docstrings and improve homepage
1 parent 8a1068a commit b45bf4e

File tree

5 files changed

+159
-28
lines changed

5 files changed

+159
-28
lines changed

cirun/client.py

+91-22
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ def set_repo(
6464
installation_id=None
6565
):
6666
"""
67-
Activate repository for Cirun
67+
Activate or deactivate a repository for Cirun.
68+
69+
This method allows you to enable or disable a repository's integration with Cirun.
70+
When activating a repository, it can also handle the installation of the Cirun
71+
GitHub App if an `installation_id` is provided and `GITHUB_TOKEN` environment
72+
variable is set.
6873
6974
Parameters
7075
----------
@@ -173,7 +178,8 @@ def _create_access_control_repo_resource_data(
173178

174179
def remove_repo_from_resources(self, org, repo, resources):
175180
"""
176-
Removes the access to the resource for the repository.
181+
Creates a Pull request in the `<org>/.cirun` repository updating the `.access.yml`
182+
to revoke access to specified resources for a repository within an organization.
177183
178184
Parameters
179185
----------
@@ -205,31 +211,40 @@ def add_repo_to_resources(
205211
policy_args=None,
206212
):
207213
"""
208-
Grants access to the resource for the repository
214+
Creates a Pull request in the `<org>/.cirun` repository updating the `.access.yml`
215+
to grant access to specified resources for a repository within an organization,
216+
with constraints for teams, roles, users, users_from_json, policy_args.
209217
210218
Parameters
211219
----------
212-
org: str
213-
GitHub Organization
214-
repo: str
215-
GitHub Repository
216-
resources: List[str]
217-
List of resources
218-
teams: List[str]
219-
List of teams
220-
roles: List[str]
221-
List of roles
222-
users: List[str]
223-
List of users
224-
users_from_json: List[str]
225-
List of users from a json url
226-
policy_args: Optional[Dict[str, Any]]
227-
Policy arguments, this is a dictionary of key values, currently the only
228-
supported argument is ``{"pull_request": True}`` or ``{"pull_request": False}``
220+
org : str
221+
The GitHub organization name.
222+
repo : str
223+
The name of the repository to which resources are to be added.
224+
resources : list of str
225+
A list of resource identifiers to grant access to.
226+
teams : list of str, optional
227+
Teams to grant access to the resources.
228+
roles : list of str, optional
229+
Roles to grant access to the resource, i.e. users with specified roles
230+
will have access to the resources.
231+
users : list of str, optional
232+
Users to grant access to the resources.
233+
users_from_json : str, optional
234+
Users specified via a JSON URL
235+
policy_args : dict, optional
236+
Additional policy arguments, such as `{"pull_request": True}` to enforce
237+
specific policies on access.
229238
230239
Returns
231240
-------
232241
requests.Response
242+
The response object from the API after attempting to add access.
243+
244+
Raises
245+
------
246+
CirunAPIException
247+
If the API call fails with an error status code.
233248
"""
234249
repository_resource_access = self._create_access_control_repo_resource_data(
235250
repo, resources, action="add", teams=teams, roles=roles,
@@ -243,6 +258,30 @@ def _get_repo_policy(self, access_yml, repo):
243258
return policy['id']
244259

245260
def get_repo_resources(self, org, repo):
261+
"""
262+
Retrieve the list of resources that a repository has access to within an organization.
263+
264+
This method parses the access control configuration to determine which resources
265+
the specified repository is permitted to access based on its assigned policies.
266+
267+
Parameters
268+
----------
269+
org : str
270+
The GitHub organization name.
271+
repo : str
272+
The repository name whose accessible resources are to be retrieved.
273+
274+
Returns
275+
-------
276+
list of str or None
277+
A list of resource identifiers that the repository has access to, or `None`
278+
if access control configuration is not found.
279+
280+
Raises
281+
------
282+
KeyError
283+
If the repository does not have an associated policy in the access control configuration.
284+
"""
246285
access_control = self.get_access_control(org)
247286
if not access_control:
248287
return
@@ -255,7 +294,28 @@ def get_repo_resources(self, org, repo):
255294
return repo_resources
256295

257296
def clouds(self, print_error=False):
258-
"""Returns all the connected cloud"""
297+
"""
298+
Retrieve all cloud providers connected to Cirun.
299+
300+
This method fetches the list of cloud providers that have been integrated
301+
with Cirun (have credentials added to cirun).
302+
303+
Parameters
304+
----------
305+
print_error : bool, optional
306+
If set to True, errors encountered during the API call will be printed.
307+
Default is False.
308+
309+
Returns
310+
-------
311+
dict
312+
A dictionary containing information about connected cloud providers.
313+
314+
Raises
315+
------
316+
CirunAPIException
317+
If the API call fails and `print_error` is False.
318+
"""
259319
response = self._get("cloud-connect")
260320
if response.status_code not in [200, 201]:
261321
if print_error:
@@ -264,7 +324,11 @@ def clouds(self, print_error=False):
264324

265325
def cloud_connect(self, name, credentials, print_error=False):
266326
"""
267-
Connect a cloud provider to cirun.
327+
Connect a new cloud provider to Cirun.
328+
329+
This method integrates a specified cloud provider with Cirun by providing the
330+
necessary credentials. Once connected, the cloud provider can be used to create
331+
GitHub Actions runners.
268332
269333
Parameters
270334
----------
@@ -277,6 +341,11 @@ def cloud_connect(self, name, credentials, print_error=False):
277341
-------
278342
dict:
279343
Response json
344+
345+
Raises
346+
------
347+
CirunAPIException
348+
If the API call fails and `print_error` is False.
280349
"""
281350

282351
data = {

docs/_static/cirun-logo-dark.jpg

7.59 KB
Loading

docs/_static/cirun-logo-light.png

42.8 KB
Loading

docs/conf.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
99

1010
project = 'cirun-py'
11-
copyright = f'{datetime.utcnow().year}, Aktech Labs'
11+
copyright = f'{datetime.utcnow().year}, Cirun Labs'
1212
author = 'Amit Kumar'
1313
release = cirun.__version__
1414

@@ -33,3 +33,7 @@
3333

3434
html_theme = "furo"
3535
html_static_path = ['_static']
36+
html_theme_options = {
37+
"light_logo": "cirun-logo-light.png",
38+
"dark_logo": "cirun-logo-dark.jpg",
39+
}

docs/index.rst

+63-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
Cirun's Python Client documentation!
22
====================================
33

4-
Cirun's API can be accessed via this client.
4+
Welcome to the official documentation for **Cirun's Python Client**. This client library allows
5+
you to seamlessly interact with Cirun's API, enabling efficient management of repositories,
6+
access controls, cloud integrations, and more directly from your Python applications.
7+
8+
.. raw:: html
9+
10+
<p align="center">
11+
<a href="https://anaconda.org/conda-forge/cirun">
12+
<img src="https://img.shields.io/conda/dn/conda-forge/cirun.svg" alt="Conda Downloads">
13+
</a>
14+
<a href="https://pypi.org/project/cirun">
15+
<img src="https://img.shields.io/pypi/v/cirun.svg" alt="PyPI Version">
16+
</a>
17+
<a href="https://pypi.org/project/cirun">
18+
<img src="https://img.shields.io/pypi/pyversions/cirun.svg" alt="PyPI Python Version">
19+
</a>
20+
<a href="https://anaconda.org/conda-forge/cirun">
21+
<img src="https://img.shields.io/badge/recipe-cirun-green.svg" alt="Conda Recipe">
22+
</a>
23+
</p>
24+
25+
+--------------------+--------------------+
26+
| |pic1| |pic2| | |pic3| |
27+
+--------------------+--------------------+
28+
29+
.. |pic1| image:: _static/cirun-logo-light.png
30+
:class: only-light
31+
:width: 200
32+
:alt: cirun logo
33+
34+
.. |pic2| image:: _static/cirun-logo-dark.jpg
35+
:class: only-dark
36+
:width: 200
37+
:alt: cirun logo
38+
39+
.. |pic3| image:: https://cirun.io/static/media/nvidia-inception-program-badge-rgb-for-screen.2f33635d.svg
40+
:width: 200
41+
:alt: nvidia inception program logo
542

643
Installation
744
============
@@ -23,12 +60,33 @@ or via `conda-forge`
2360

2461
api
2562

63+
Features
64+
========
65+
66+
Cirun's Python Client offers a following set of features to help you manage cirun integration with
67+
your GitHub Organization:
68+
69+
- **Repository Management**: Connect, activate, and deactivate repositories integrated with Cirun.
70+
- **Access Control**: Define and update access permissions for repositories, including teams, roles, and users.
71+
- **Cloud Integrations**: Connect and manage various cloud providers directly through the client.
72+
- **GitHub App Installation**: Simplify the installation of Cirun's GitHub App on your repositories.
73+
2674
Contributing
2775
============
2876

29-
There are multiple ways you can contibute to cirun client
77+
There are multiple ways you can contribute to cirun client
3078

31-
* Add missing documentation.
32-
* Report bugs.
79+
- **Add Missing Documentation**: Help improve the clarity and comprehensiveness of our docs.
80+
- **Report Bugs**: If you encounter any issues, please report them.
81+
- **Feature Requests**: Suggest new features or improvements.
82+
- **Submit Pull Requests**: Implement bug fixes or new features and submit your code for review.
83+
84+
.. toctree::
85+
:hidden:
86+
:caption: Meta
3387

34-
Use github's Pull request/issues feature for all contributions.
88+
PyPI <https://pypi.org/project/cirun/>
89+
GitHub <https://github.com/aktechlabs/cirun-py/>
90+
Cirun <https://cirun.io>
91+
Cirun Docs <https://docs.cirun.io>
92+
X <https://x.com/CirunHQ>

0 commit comments

Comments
 (0)