Skip to content

Commit 27ab591

Browse files
authored
Make the repo release ready (#1)
* Add unittests and the integrationtests * Update the tests and the src * Add coverage badge * Reformat the files * Add new functions and the corresponding tests * Update the integrationtest * Add coverage badge
1 parent 894721e commit 27ab591

25 files changed

+2243
-133
lines changed

.coveragerc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[run]
2+
branch = True
3+
omit =
4+
*/setup.py
5+
source = .
6+
7+
[report]
8+
omit =
9+
*/setup.py
10+
fail_under = 80
11+
show_missing = True
12+
skip_covered = False
13+
exclude_lines =
14+
# Have to re-enable the standard pragma
15+
pragma: no cover
16+
17+
# Don't complain if tests don't hit defensive assertion code:
18+
raise AssertionError
19+
raise NotImplementedError
20+
21+
# Don't complain if non-runnable code isn't run:
22+
if __name__ == .__main__.:

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
ignore = E203, E266, E501, W503
3+
max-line-length = 120
4+
max-complexity = 20
5+
select = B,C,D,E,F,W,T4,B902,B950
6+
exclude = venc,.git
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Integrationtest
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Install the requirements
18+
run: pip install -r requirements.txt
19+
20+
- name: Execute the integrationtests
21+
run: python3 -m unittest discover tests/integrationtest
22+
env:
23+
GRAFANA_HOST: ${{ secrets.GRAFANA_HOST }}
24+
GRAFANA_TOKEN: ${{ secrets.GRAFANA_TOKEN }}
25+
GRAFANA_DASHBOARD_PATH: ${{ secrets.GRAFANA_DASHBOARD_PATH }}
26+
GRAFANA_DASHBOARD_NAME: ${{ secrets.GRAFANA_DASHBOARD_NAME }}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build and publish
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
7+
jobs:
8+
9+
build-and-publish:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: ['3.x']
14+
15+
steps:
16+
- name: Checkout the repository and the branch
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
architecture: x64
24+
cache: 'pip'
25+
26+
- name: Install the requirements
27+
run: pip install -r requirements.txt
28+
29+
- name: Install pypa/build
30+
run: >-
31+
python -m
32+
pip install
33+
build
34+
--user
35+
36+
- name: Build a binary wheel and a source tarball
37+
run: >-
38+
python -m
39+
build
40+
--sdist
41+
--wheel
42+
--outdir dist/
43+
44+
- name: Publish distribution package to PyPI
45+
if: startsWith(github.ref, 'refs/tags')
46+
uses: pypa/gh-action-pypi-publish@master
47+
with:
48+
password: ${{ secrets.PYPI_API_TOKEN }}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: PR checks
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: [ '3.x' ]
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
architecture: x64
23+
cache: 'pip'
24+
25+
- name: Install the requirements
26+
run: pip install -r requirements.txt
27+
28+
- name: Execute the unittests
29+
run: python3 -m unittest discover tests/unittests
30+
31+
lint:
32+
runs-on: ubuntu-latest
33+
strategy:
34+
matrix:
35+
python-version: [ '3.x' ]
36+
37+
steps:
38+
- uses: actions/checkout@v2
39+
40+
- name: Set up Python
41+
uses: actions/setup-python@v2
42+
with:
43+
python-version: ${{ matrix.python-version }}
44+
architecture: x64
45+
cache: 'pip'
46+
47+
- name: Install the requirements
48+
run: pip install -r requirements.txt
49+
50+
- name: Execute the linting checks
51+
uses: reviewdog/[email protected]
52+
with:
53+
github_token: ${{ secrets.GITHUB_TOKEN }}
54+
flake8_args: --config=.flake8
55+
56+
coverage:
57+
runs-on: ubuntu-latest
58+
strategy:
59+
matrix:
60+
python-version: [ '3.x' ]
61+
62+
steps:
63+
- uses: actions/checkout@v2
64+
with:
65+
persist-credentials: false
66+
fetch-depth: 0
67+
68+
- name: Set up Python
69+
uses: actions/setup-python@v2
70+
with:
71+
python-version: ${{ matrix.python-version }}
72+
architecture: x64
73+
cache: 'pip'
74+
75+
- name: Install the requirements
76+
run: pip install -r requirements.txt && pip install pytest pytest-cov coverage-badge
77+
78+
- name: Generate the coverage report
79+
run: export PYTHONPATH=$PWD && pytest --junitxml=pytest.xml --cov=. tests/unittests | tee pytest-coverage.txt
80+
81+
- name: Execute the coverage checks
82+
uses: MishaKav/[email protected]
83+
with:
84+
github_token: ${{ secrets.GITHUB_TOKEN }}
85+
pytest-coverage-path: ./pytest-coverage.txt
86+
junitxml-path: ./pytest.xml
87+
hide-badge: true
88+
create-new-commit: true
89+
90+
- name: "Check if coverage badge file existence"
91+
id: check_files
92+
uses: andstor/file-existence-action@v1
93+
with:
94+
files: "docs/coverage.svg"
95+
96+
- name: Generate coverage badge
97+
if: steps.check_files.outputs.files_exists == 'false'
98+
run: coverage-badge -o docs/coverage.svg -f
99+
100+
- name: Commit files
101+
if: steps.check_files.outputs.files_exists == 'false'
102+
run: |
103+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
104+
git config --local user.name "github-actions[bot]"
105+
git add --force docs/coverage.svg
106+
git commit -m "Add coverage badge"
107+
108+
- name: Push changes
109+
if: steps.check_files.outputs.files_exists == 'false'
110+
uses: ad-m/github-push-action@master
111+
with:
112+
github_token: ${{ secrets.GITHUB_TOKEN }}
113+
branch: ${{ github.head_ref }}
114+
force: true

README.md

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,84 @@
1-
# grafana_api_sdk
2-
The repository includes an SDK for the Grafana API
3-
4-
## TODO
5-
- Documentation
6-
- Docstrings
7-
- PYPI support
1+
# Grafana API SDK ![Coverage report](https://github.com/ZPascal/grafana_api_sdk/blob/main/docs/coverage.svg)
2+
The repository includes an SDK for the Grafana API. It's possible to communicate with the Grafana API endpoints. Another feature of the SDK is the possibility to specify the used folder for the dashboard.
83

94
## Currently, supported features
105

11-
- Get a Dashboard by uid
12-
- Get folder id by dashboard path
13-
- Get all folder ids and folder names
14-
- Specify the grafana dashboard folder
6+
### Dashboard
157
- Create/ Update a dashboard
168
- Delete a dashboard
9+
- Get permissions of a dashboard
10+
- Update the permissions of a dashboard
11+
- Get all dashboard versions
12+
- Get dashboard version of a specific dashboard
13+
- Restore a dashboard version of a specific dashboard
14+
- Compare two dashboard versions and extract the diff between booth dashboards
15+
16+
### Folder
17+
- Get folder id by dashboard path
18+
- Get all folder ids and folder names
19+
- Get all folders
20+
- Get folder by uid
21+
- Get folder by id
22+
- Create a folder
23+
- Update a folder
24+
- Delete a folder
25+
- Get permissions for a folder
26+
- Update permissions for a folder
27+
28+
### Search
29+
- Execute a custom query against the Grafana search endpoint
30+
31+
## Feature timeline
32+
33+
The following table describes the plan to implement the rest of the Grafana API functionality. Please, open an issue and vote them up, if you prefer a faster implementation of an API functionality.
34+
35+
| API endpoint group | Implementation week | Maintainer | PR | State |
36+
|:------------------:|:-------------------:|:----------:|:--:|:-----:|
37+
| [Admin HTTP API](https://grafana.com/docs/grafana/latest/http_api/admin/) | | | | |
38+
| [Alerting HTTP API](https://grafana.com/docs/grafana/latest/http_api/alerting/) | 4 | [ZPascal](https://github.com/ZPascal) | | Planned |
39+
| [Alerting Notification Channels HTTP API](https://grafana.com/docs/grafana/latest/http_api/alerting_notification_channels/) | 4 | [ZPascal](https://github.com/ZPascal) | | Planned |
40+
| [Annotations HTTP API](https://grafana.com/docs/grafana/latest/http_api/annotations/) | | | | |
41+
| [Authentication HTTP API](https://grafana.com/docs/grafana/latest/http_api/auth/) | | | | |
42+
| [Data source HTTP API](https://grafana.com/docs/grafana/latest/http_api/data_source/) | 5 | [ZPascal](https://github.com/ZPascal) | | Planned |
43+
| [Datasource Permissions HTTP API](https://grafana.com/docs/grafana/latest/http_api/datasource_permissions/) | | | | |
44+
| [External Group Sync HTTP API](https://grafana.com/docs/grafana/latest/http_api/external_group_sync/) | | | | |
45+
| [Fine-grained access control HTTP API](https://grafana.com/docs/grafana/latest/http_api/access_control/) | | | | |
46+
| [HTTP Preferences API](https://grafana.com/docs/grafana/latest/http_api/preferences/) | | | | |
47+
| [HTTP Snapshot API](https://grafana.com/docs/grafana/latest/http_api/snapshot/) | | | | |
48+
| [Library Element HTTP API](https://grafana.com/docs/grafana/latest/http_api/library_element/) | | | | |
49+
| [Licensing HTTP API](https://grafana.com/docs/grafana/latest/http_api/licensing/) | | | | |
50+
| [Organization HTTP API](https://grafana.com/docs/grafana/latest/http_api/org/) | | | | |
51+
| [Other HTTP API](https://grafana.com/docs/grafana/latest/http_api/other/) | | | | |
52+
| [Playlist HTTP API](https://grafana.com/docs/grafana/latest/http_api/playlist/) | | | | |
53+
| [Reporting API](https://grafana.com/docs/grafana/latest/http_api/reporting/) | | | | |
54+
| [Short URL HTTP API](https://grafana.com/docs/grafana/latest/http_api/short_url/) | | | | |
55+
| [Team HTTP API](https://grafana.com/docs/grafana/latest/http_api/team/) | | | | |
56+
| [User HTTP API](https://grafana.com/docs/grafana/latest/http_api/user/) | | | | |
57+
58+
## Installation
59+
60+
`pip install grafana-api-sdk`
61+
62+
## Example
63+
64+
```python
65+
import json
66+
67+
from grafana_api.model import APIModel
68+
from grafana_api.dashboard import Dashboard
69+
70+
model: APIModel = APIModel(host="test", token="test")
71+
72+
dashboard: Dashboard = Dashboard(model)
1773

18-
## Installation & Requirements
74+
with open("/tmp/test/test.json") as file:
75+
json_dashboard = json.load(file)
1976

20-
### Programs & tools to install
77+
dashboard.create_or_update_dashboard(message="Create a new test dashboard", dashboard_json=json_dashboard, dashboard_path="test")
78+
```
2179

22-
- json-extensions
23-
- requests
80+
## Templating
81+
If you want to template your JSON document based on a predefined folder structure you can check out one of my other [project](https://github.com/ZPascal/grafana_dashboard_templater) and integrate the functionality inside your code.
2482

2583
## Contribution
2684
If you would like to contribute something, have an improvement request, or want to make a change inside the code, please open a pull request.
File renamed without changes.

docs/coverage.svg

Lines changed: 21 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)