Skip to content

Commit 49a1901

Browse files
authored
Merge pull request #12 from Girish5tri/triager-tool-enhancements
Containerising and automating the tools used for Bug triage and CI health reports
2 parents d275493 + 3ae9e13 commit 49a1901

17 files changed

+732
-164
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Bug Triage Workflow
2+
3+
on:
4+
schedule:
5+
# Run bug triage every Wednesday at 2:30 PM IST (9:00 AM UTC)
6+
- cron: "0 9 * * 3"
7+
workflow_dispatch: # for manual triggering of the workflow
8+
9+
jobs:
10+
run-bug-triage:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
26+
- name: Run Bug Triage
27+
env:
28+
EMAIL_SENDER: ${{ secrets.EMAIL_SENDER }}
29+
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
30+
GITHUB_TOKEN: ${{ github.token }}
31+
MAINTAINERS: ${{ secrets.MAINTAINERS }}
32+
REPO_CONFIG: ${{ secrets.REPO_CONFIG }}
33+
run: |
34+
python -m triager --bugs -c config.yaml --log --send-email

.github/workflows/ci_workflow.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Nightly CI Report Workflow
2+
3+
on:
4+
schedule:
5+
# Run CI report daily at 12:00 PM IST (6:30 AM UTC)
6+
- cron: "30 6 * * *"
7+
workflow_dispatch: # for manual triggering of the workflow
8+
9+
jobs:
10+
run-ci-report:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
26+
- name: Run CI Report
27+
env:
28+
EMAIL_SENDER: ${{ secrets.EMAIL_SENDER }}
29+
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
30+
GITHUB_TOKEN: ${{ github.token }}
31+
MAINTAINERS: ${{ secrets.MAINTAINERS }}
32+
REPO_CONFIG: ${{ secrets.REPO_CONFIG }}
33+
run: |
34+
python -m triager --ci -c config.yaml --log --send-email

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*.code-workspace
44
__pycache__/
55
*.egg-info
6+
.env
7+
.flake8

.pre-commit-config.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.6.0
5+
hooks:
6+
- id: check-merge-conflict
7+
- id: check-symlinks
8+
- id: debug-statements
9+
- id: end-of-file-fixer
10+
- id: trailing-whitespace
11+
12+
- repo: https://github.com/asottile/add-trailing-comma
13+
rev: v3.1.0
14+
hooks:
15+
- id: add-trailing-comma
16+
17+
- repo: https://github.com/pycontribs/mirrors-prettier
18+
rev: "v3.3.3"
19+
hooks:
20+
- id: prettier
21+
entry: env CI=1 bash -c "prettier --list-different . || ec=$? && prettier --loglevel=error --write . && exit $ec"
22+
pass_filenames: false
23+
args: []
24+
additional_dependencies:
25+
- prettier
26+
- prettier-plugin-toml
27+
28+
- repo: https://github.com/PyCQA/isort
29+
rev: 5.13.2
30+
hooks:
31+
- id: isort
32+
name: Sort import statements using isort
33+
args: ["--filter-files"]
34+
35+
- repo: https://github.com/psf/black
36+
rev: 24.8.0
37+
hooks:
38+
- id: black
39+
40+
- repo: https://github.com/pycqa/flake8
41+
rev: 7.1.1
42+
hooks:
43+
- id: flake8

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY . .
9+
10+
RUN useradd -m myuser && chown -R myuser:myuser /app
11+
USER myuser
12+
13+
ENV PYTHONPATH=/app
14+
15+
CMD ["python", "-m", "triager"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
671671
may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674-
<https://www.gnu.org/licenses/why-not-lgpl.html>.
674+
<https://www.gnu.org/licenses/why-not-lgpl.html>.

README.md

Lines changed: 165 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
2-
31
# Ansible Network Triager
42

53
Set repositories of interest and run with `triager -c /path/to/config.yaml`
64

7-
This tool assists in weekly bug triages by fetching all issues and pull-requests
8-
from repositories specified in the config file that were created (or updated)
9-
since a pre-defined number of days (`timedelta`). These are also filtered by the `labels`
10-
set in the config file. In case no `labels` are specified, then items that are
11-
currently unassigned are pulled.
5+
This tool assists in weekly bug triages and CI reports by fetching all issues, pull requests, and CI statuses from repositories specified in the configuration file. It retrieves items that were created (or updated) since a pre-defined number of days (`timedelta`). These are also filtered by the `labels` set in the config file. In case no `labels` are specified, then items that are currently unassigned are pulled.
126

137
By default, this prints out a table built from the fetched content to the console.
148
When run with `--send-email` it also emails this table to all the listed maintainers.
@@ -17,22 +11,185 @@ When run with `--send-email` it also emails this table to all the listed maintai
1711

1812
pip install git+https://github.com/ansible-network/ansible-network-triager.git@master
1913

14+
git clone https://github.com/ansible-network/ansible-network-triager.git
15+
16+
cd ansible-network-triager
17+
18+
pip install -r requirements.txt
19+
20+
## Configuration
21+
22+
1. add your details such as organization_name, workflow_name in `config.yaml` file:
23+
24+
organization_name: "Ansible Networking"
25+
workflow_name: "tests.yml"
26+
timedelta: 14
27+
28+
2. Create a `.env` file in the root of your directory and add these details:
29+
30+
EMAIL_SENDER=[email protected]
31+
EMAIL_PASSWORD=your_email_password
32+
MAINTAINERS=[{"name": "Your Name", "email": "[email protected]"}]
33+
#GITHUB_TOKEN=your_github_token (optional - enter your github token here to make authenticated requests or comment this line to make unauthenticated API requests)
34+
REPO_CONFIG = {
35+
<organization>: {
36+
"ci_and_bug_repos": [<list of repositories>],
37+
"bug_specific_repos": [<list of repositories>]
38+
}
39+
}
40+
2041
## Usage
42+
43+
### Local Usage
44+
45+
1. Run the bug scrub:
46+
47+
triager --bugs -c config.yaml --log --send-email
48+
49+
2. Run the CI report:
50+
51+
triager --ci -c config.yaml --log --send-email
52+
53+
### Docker Usage
54+
55+
1. Build the Docker image:
56+
57+
sudo docker-compose build
58+
59+
2. Run the bug scrub:
60+
61+
sudo docker-compose run triager
62+
63+
3. Run the CI report:
64+
65+
sudo docker-compose run ci_report
66+
67+
### GitHub Actions
68+
69+
This tool uses GitHub Actions for automated reporting. To set up the workflows:
70+
71+
1. Store your secrets in GitHub Actions:
72+
a) Go to your GitHub repository
73+
b) Click on "Settings" tab
74+
c) In the left sidebar, click on "Secrets and variables", then "Actions"
75+
d) Click on "New repository secret"
76+
e) Add the following secrets:
77+
78+
- `EMAIL_SENDER`: Your tool's email address for sending reports
79+
- `EMAIL_PASSWORD`: Your tool's email password
80+
- `MAINTAINERS`: A JSON string containing the maintainers' information
81+
- `REPO_CONFIG`: A JSON string containing the repository configuration
82+
83+
2. The following workflows are available in `.github/workflows/`:
84+
85+
- `bug_triager_workflow.yml`: Runs weekly bug triage
86+
- `ci_workflow.yml`: Runs daily CI status report
87+
88+
### Workflow Details
89+
90+
#### Bug Triage Workflow
91+
92+
This workflow runs every Wednesday at 2:30 PM IST (9:00 AM UTC) and can also be triggered manually.
93+
94+
```yaml
95+
name: Bug Triage Workflow
96+
97+
on:
98+
schedule:
99+
- cron: '0 9 * * 3'
100+
workflow_dispatch:
101+
102+
jobs:
103+
run-bug-triage:
104+
runs-on: ubuntu-latest
105+
steps:
106+
- uses: actions/checkout@v2
107+
- uses: actions/setup-python@v2
108+
with:
109+
python-version: '3.x'
110+
- run: pip install -r requirements.txt
111+
- run: python -m triager --bugs -c example-config.yaml --log --send-email
112+
env:
113+
EMAIL_SENDER: ${{ secrets.EMAIL_SENDER }}
114+
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
115+
GITHUB_TOKEN: ${{ github.token }}
116+
MAINTAINERS: ${{ secrets.MAINTAINERS }}
117+
REPO_CONFIG: ${{ secrets.REPO_CONFIG }}
118+
119+
#### CI Report Workflow
120+
121+
This workflow runs daily at 12:00 PM IST (6:30 AM UTC) and can also be triggered manually.
122+
123+
''''yaml
124+
name: Nightly CI Report Workflow
125+
126+
on:
127+
schedule:
128+
- cron: '30 6 * * *'
129+
workflow_dispatch:
130+
131+
jobs:
132+
run-ci-report:
133+
runs-on: ubuntu-latest
134+
steps:
135+
- uses: actions/checkout@v2
136+
- uses: actions/setup-python@v2
137+
with:
138+
python-version: '3.x'
139+
- run: pip install -r requirements.txt
140+
- run: python -m triager --ci -c example-config.yaml --log --send-email
141+
env:
142+
EMAIL_SENDER: ${{ secrets.EMAIL_SENDER }}
143+
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
144+
GITHUB_TOKEN: ${{ github.token }}
145+
MAINTAINERS: ${{ secrets.MAINTAINERS }}
146+
REPO_CONFIG: ${{ secrets.REPO_CONFIG }}
147+
148+
149+
## Options
150+
21151
Options | Usage
22152
--- | ---
23153
'-c'|Path to config file (selects 'config.yaml' in current working directory by default)
154+
'--bugs'|Generate a bug scrub report
155+
'--ci'|Generate a CI report
24156
'--log'|Print logging information on the console (default level set to INFO)
25157
'--log-to-file'|Dump logging information to a specified file (if no file is specified, the data will be written to /tmp/triager_{{ timestamp }}.log)
26158
'--debug'|Bumps logging level to DEBUG
27159
'--send-email'|Send the triaged table as an email to the list of maintainers
28160

161+
## Pre-commit Hooks
162+
163+
This tool uses pre-commit hooks to ensure code quality. The hooks perform the following checks:
164+
165+
- Check for merge conflicts
166+
- Verify symlinks
167+
- Detect debug statements
168+
- Fix end of files
169+
- Remove trailing whitespace
170+
- Add trailing commas
171+
- Format code with Prettier
172+
- Sort import statements with isort
173+
- Format Python code with Black
174+
- Lint Python code with Flake8
175+
176+
To use pre-commit:
177+
178+
1. Install pre-commit: `pip install pre-commit`
179+
2. Install the git hook scripts: `pre-commit install`
180+
3. (Optional) Run against all files: `pre-commit run --all-files`
181+
182+
Pre-commit will now run automatically on `git commit`. You can also run it manually on staged files with `pre-commit run`.
183+
184+
29185
## Notes
30186
- An example config file (example-config.yaml) has been placed in this repository for reference.
31-
- Tested with Python 3.6
187+
- Tested with Python 3.11
32188
- This tool gets installed as a part of `ansible-network-tools` package.
33189

34190
## Licensing
35191

36192
GNU General Public License v3.0 or later.
37193

38194
See [LICENSE](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text.
195+
```

config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
organization_name: "Ansible Networking"
2+
workflow_name: "tests.yml"
3+
timedelta: 14

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3"
2+
services:
3+
triager:
4+
build: .
5+
env_file: .env
6+
command: python -m triager --bugs -c config.yaml --log --send-email
7+
8+
ci_report:
9+
build: .
10+
env_file: .env
11+
command: python -m triager --ci -c config.yaml --log --send-email

0 commit comments

Comments
 (0)