Skip to content

Commit 3e81538

Browse files
authored
feat: add additional models, handlers
2 parents 8155cde + d6fd356 commit 3e81538

File tree

14 files changed

+555
-159
lines changed

14 files changed

+555
-159
lines changed

README.md

Lines changed: 46 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# GitHub Actions Aggregator Service
1+
# GitHub Actions Aggregator
22

3-
A Go-based service to aggregate and analyze data from GitHub Actions workflows across multiple repositories. This application provides insights into workflow runs, success rates, failure rates, and other statistics over customizable time ranges.
3+
GitHub Actions Aggregator is a Go-based service designed to collect, aggregate, and analyze data from GitHub Actions workflows across multiple repositories. This application provides valuable insights into workflow runs, success rates, failure rates, and other statistics over customizable time ranges.
44

55
## Table of Contents
66

@@ -17,7 +17,7 @@ A Go-based service to aggregate and analyze data from GitHub Actions workflows a
1717

1818
## Features
1919

20-
- **OAuth 2.0 Authentication**: Securely authenticate users via GitHub OAuth.
20+
- **OAuth 2.0 Authentication**: Secure user authentication via GitHub OAuth.
2121
- **Data Collection**:
2222
- **Webhooks**: Receive real-time updates on workflow events.
2323
- **Polling**: Periodically poll GitHub API to ensure data completeness.
@@ -29,11 +29,10 @@ A Go-based service to aggregate and analyze data from GitHub Actions workflows a
2929

3030
## Prerequisites
3131

32-
- **Go**: Version 1.18 or higher.
33-
- **GitHub Account**: For OAuth authentication and API access.
34-
- **PostgreSQL**: For storing data.
35-
- **Redis** (optional): For caching (if implemented).
36-
- **Docker** (optional): For containerization and deployment.
32+
- Go (version 1.18 or higher)
33+
- PostgreSQL
34+
- GitHub Account (for OAuth authentication and API access)
35+
- Docker (optional, for containerization)
3736

3837
## Installation
3938

@@ -44,16 +43,15 @@ A Go-based service to aggregate and analyze data from GitHub Actions workflows a
4443
cd github-actions-aggregator
4544
```
4645

47-
2. **Install Dependencies**
48-
49-
```bash
46+
2. Install dependencies:
47+
```
5048
go mod download
5149
```
5250

53-
3. **Set Up Environment Variables**
54-
51+
3. Set up environment variables:
5552
Create a `.env` file or export the required environment variables:
5653

54+
5755
```bash
5856
export GITHUB_CLIENT_ID="your_github_client_id"
5957
export GITHUB_CLIENT_SECRET="your_github_client_secret"
@@ -63,11 +61,12 @@ A Go-based service to aggregate and analyze data from GitHub Actions workflows a
6361
export SERVER_PORT="8080"
6462
```
6563

64+
6665
## Configuration
6766

6867
Configuration can be managed via a `config.yaml` file in the `configs/` directory or through environment variables.
6968

70-
**Example `config.yaml`:**
69+
Example `config.yaml`:
7170

7271
```yaml
7372
server:
@@ -83,126 +82,68 @@ github:
8382
webhook_secret: "your_webhook_secret"
8483
```
8584
86-
**Note:** Environment variables override values in the configuration file.
85+
Note: Environment variables override values in the configuration file.
8786
8887
## Usage
8988
90-
### Running the Application
91-
92-
1. **Run Database Migrations**
93-
94-
```bash
95-
./scripts/migrate.sh
89+
1. Run database migrations:
90+
```
91+
./scripts/migrate.sh up
9692
```
9793

98-
2. **Start the Application**
99-
100-
```bash
94+
2. Start the application:
95+
```
10196
go run cmd/server/main.go
10297
```
10398

104-
### Accessing the Application
105-
106-
- **Login with GitHub**: Navigate to `http://localhost:8080/login` to authenticate via GitHub.
107-
- **API Requests**: Use tools like `curl` or Postman to interact with the API endpoints.
99+
3. Access the application:
100+
- Login with GitHub: Navigate to `http://localhost:8080/login`
101+
- API Requests: Use tools like `curl` or Postman to interact with the API endpoints
108102

109103
## API Endpoints
110104

111-
### Authentication
112-
113105
- `GET /login`: Redirects the user to GitHub for OAuth authentication.
114106
- `GET /callback`: Handles the OAuth callback from GitHub.
115-
116-
### Workflow Statistics
117-
118107
- `GET /workflows/:id/stats`: Retrieves statistics for a specific workflow.
108+
- `GET /repositories/:id/workflows`: Get all workflows for a repository
109+
- `GET /workflows/:id/runs`: Get all runs for a workflow
110+
- `GET /runs/:id`: Get a specific run
111+
- `GET /jobs/:id`: Get a specific job
112+
- `GET /jobs/:id/steps`: Get all steps for a job
113+
- `GET /jobs/:id/stats`: Get stats for a job
119114

120-
**Query Parameters:**
121-
122-
- `start_time` (optional): Start of the time range (ISO 8601 format).
123-
- `end_time` (optional): End of the time range (ISO 8601 format).
124-
125-
**Example Request:**
126-
127-
Explicit time range:
128-
129-
```http
130-
GET /workflows/123/stats?start_time=2023-09-01T00:00:00Z&end_time=2023-09-30T23:59:59Z
131-
```
132-
133-
Relative time range:
134-
135-
```http
136-
GET /workflows/123/stats?start_time=24_hours&end_time=now
137-
```
138-
139-
**Example Response:**
140-
141-
```json
142-
{
143-
"workflow_id": 123,
144-
"workflow_name": "CI Build and Test",
145-
"total_runs": 200,
146-
"success_count": 150,
147-
"failure_count": 30,
148-
"cancelled_count": 10,
149-
"timed_out_count": 5,
150-
"action_required_count": 5,
151-
"success_rate": 75.0,
152-
"failure_rate": 15.0,
153-
"cancelled_rate": 5.0,
154-
"timed_out_rate": 2.5,
155-
"action_required_rate": 2.5,
156-
"start_time": "2023-09-01T00:00:00Z",
157-
"end_time": "2023-09-30T23:59:59Z"
158-
}
159-
```
115+
For detailed information on request parameters and response formats, please refer to the API documentation.
160116

161117
## Authentication
162118

163-
### Setting Up OAuth with GitHub
164-
165-
1. **Register a New OAuth Application**
166-
167-
- Go to [GitHub Developer Settings](https://github.com/settings/developers).
168-
- Click on **"New OAuth App"**.
119+
1. Register a new OAuth application on GitHub:
120+
- Go to GitHub Developer Settings
121+
- Click on "New OAuth App"
169122
- Fill in the application details:
170-
- **Application Name**
171-
- **Homepage URL**: `http://localhost:8080`
172-
- **Authorization Callback URL**: `http://localhost:8080/callback`
173-
- Obtain your **Client ID** and **Client Secret**.
174-
175-
2. **Configure Application Credentials**
123+
- Application Name
124+
- Homepage URL: `http://localhost:8080`
125+
- Authorization Callback URL: `http://localhost:8080/callback`
126+
- Obtain your Client ID and Client Secret
176127

128+
2. Configure application credentials:
177129
Set your `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` in your environment variables or `config.yaml`.
178130

179-
### Permissions and Scopes
180-
181-
Ensure that your GitHub OAuth application has the necessary scopes:
182-
183-
- `read:user`
184-
- `repo`
185-
- `workflow`
131+
Ensure that your GitHub OAuth application has the necessary scopes: `read:user`, `repo`, and `workflow`.
186132

187133
## Testing
188134

189-
### Running Unit Tests
190-
191-
```bash
135+
Run unit tests:
136+
```
192137
go test ./tests/unit/...
193138
```
194139

195-
### Running Integration Tests
196-
197-
```bash
140+
Run integration tests:
141+
```
198142
go test ./tests/integration/...
199143
```
200144

201-
### Test Coverage
202-
203-
You can generate a test coverage report using:
204-
205-
```bash
145+
Generate a test coverage report:
146+
```
206147
go test -coverprofile=coverage.out ./...
207148
go tool cover -html=coverage.out
208149
```
@@ -241,11 +182,11 @@ Contributions are welcome! Please follow these steps:
241182

242183
6. **Create a Pull Request**
243184

244-
Go to the original repository and open a pull request.
185+
For more details, please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file.
245186

246187
## License
247188

248-
This project is licensed under the [MIT License](LICENSE).
189+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
249190

250191
---
251192

cmd/server/main.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ func main() {
3737
// Initialize GitHub client
3838
githubClient := github.NewClient(cfg.GitHub.AccessToken)
3939

40-
workerPool := worker.NewWorkerPool(database, cfg.WorkerPoolSize)
41-
workerPool.Start()
40+
// Initialize worker pool for polling
41+
pollingWorkerPool := worker.NewWorkerPool(database, cfg.PollingWorkerPoolSize)
42+
pollingWorkerPool.Start()
43+
44+
// Initialize worker pool for webhooks
45+
webhookWorkerPool := worker.NewWorkerPool(database, cfg.WebhookWorkerPoolSize)
46+
webhookWorkerPool.Start()
4247

4348
// Start the API server
44-
go api.StartServer(cfg, database, githubClient, workerPool)
49+
go api.StartServer(cfg, database, githubClient, webhookWorkerPool)
4550

4651
// Set up graceful shutdown
4752
quit := make(chan os.Signal, 1)
@@ -50,9 +55,9 @@ func main() {
5055

5156
log.Println("Shutting down server...")
5257

53-
// Stop the worker pool
54-
workerPool.Stop()
55-
58+
// Stop the worker pools
59+
webhookWorkerPool.Stop()
60+
pollingWorkerPool.Stop()
5661
log.Println("Server exiting")
5762
}
5863

docs/DESIGN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Design
2+
3+
Instead of querying the GitHub API for each request, we will query our database. This will be faster and cheaper. At the organization level, a webhook is created that sends events to our server.
4+
5+
## API
6+
7+
### Endpoints
8+
9+
#### GET /repositories/:id/workflows
10+
11+
#### GET /workflows/:id/stats
12+
13+
#### GET /workflows/:id/runs
14+
15+
#### GET /runs/:id
16+
17+
#### GET /jobs/:id

0 commit comments

Comments
 (0)