Skip to content

Commit 51e10fe

Browse files
Alec CunninghamAlec Cunningham
Alec Cunningham
authored and
Alec Cunningham
committed
fix: overwrites from rebase
1 parent e09fd3b commit 51e10fe

17 files changed

+688
-71
lines changed

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM golang:1.18-alpine
2+
3+
# Install migrate tool
4+
RUN apk add --no-cache curl bash && \
5+
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-amd64.tar.gz | \
6+
tar xvz && mv migrate.linux-amd64 /usr/local/bin/migrate
7+
8+
# Set working directory
9+
WORKDIR /app
10+
11+
# Copy go mod and sum files
12+
COPY go.mod go.sum ./
13+
14+
# Download dependencies
15+
RUN go mod download
16+
17+
# Copy the source code
18+
COPY . .
19+
20+
# Expose port
21+
EXPOSE 8080
22+
23+
# Run migrations and start the application
24+
CMD ["sh", "-c", "./scripts/migrate.sh up && go run cmd/server/main.go"]

README.md

Lines changed: 244 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,244 @@
1-
# github-actions-aggregator
1+
# GitHub Actions Aggregator Service
2+
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.
4+
5+
## Table of Contents
6+
7+
- [Features](#features)
8+
- [Prerequisites](#prerequisites)
9+
- [Installation](#installation)
10+
- [Configuration](#configuration)
11+
- [Usage](#usage)
12+
- [API Endpoints](#api-endpoints)
13+
- [Authentication](#authentication)
14+
- [Testing](#testing)
15+
- [Contributing](#contributing)
16+
- [License](#license)
17+
18+
## Features
19+
20+
- **OAuth 2.0 Authentication**: Securely authenticate users via GitHub OAuth.
21+
- **Data Collection**:
22+
- **Webhooks**: Receive real-time updates on workflow events.
23+
- **Polling**: Periodically poll GitHub API to ensure data completeness.
24+
- **Data Aggregation**: Compute statistics like success rates, failure rates, and more.
25+
- **API Endpoints**: Expose RESTful APIs for accessing aggregated data.
26+
- **Background Processing**: Use worker pools to handle asynchronous tasks.
27+
- **Configurable**: Easily adjust settings like polling intervals and webhook secrets.
28+
- **Secure**: Validate webhook payloads and protect routes with authentication middleware.
29+
30+
## Prerequisites
31+
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.
37+
38+
## Installation
39+
40+
1. **Clone the Repository**
41+
42+
```bash
43+
git clone https://github.com/yourusername/github-actions-aggregator.git
44+
cd github-actions-aggregator
45+
```
46+
47+
2. **Install Dependencies**
48+
49+
```bash
50+
go mod download
51+
```
52+
53+
3. **Set Up Environment Variables**
54+
55+
Create a `.env` file or export the required environment variables:
56+
57+
```bash
58+
export GITHUB_CLIENT_ID="your_github_client_id"
59+
export GITHUB_CLIENT_SECRET="your_github_client_secret"
60+
export GITHUB_ACCESS_TOKEN="your_github_access_token"
61+
export GITHUB_WEBHOOK_SECRET="your_webhook_secret"
62+
export DATABASE_URL="postgres://username:password@localhost:5432/yourdbname?sslmode=disable"
63+
export SERVER_PORT="8080"
64+
```
65+
66+
## Configuration
67+
68+
Configuration can be managed via a `config.yaml` file in the `configs/` directory or through environment variables.
69+
70+
**Example `config.yaml`:**
71+
72+
```yaml
73+
server:
74+
port: "8080"
75+
76+
log:
77+
level: "info"
78+
79+
github:
80+
client_id: "your_github_client_id"
81+
client_secret: "your_github_client_secret"
82+
access_token: "your_github_access_token"
83+
webhook_secret: "your_webhook_secret"
84+
```
85+
86+
**Note:** Environment variables override values in the configuration file.
87+
88+
## Usage
89+
90+
### Running the Application
91+
92+
1. **Run Database Migrations**
93+
94+
```bash
95+
./scripts/migrate.sh
96+
```
97+
98+
2. **Start the Application**
99+
100+
```bash
101+
go run cmd/server/main.go
102+
```
103+
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.
108+
109+
## API Endpoints
110+
111+
### Authentication
112+
113+
- `GET /login`: Redirects the user to GitHub for OAuth authentication.
114+
- `GET /callback`: Handles the OAuth callback from GitHub.
115+
116+
### Workflow Statistics
117+
118+
- `GET /workflows/:id/stats`: Retrieves statistics for a specific workflow.
119+
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+
```http
128+
GET /workflows/123/stats?start_time=2023-09-01T00:00:00Z&end_time=2023-09-30T23:59:59Z
129+
```
130+
131+
**Example Response:**
132+
133+
```json
134+
{
135+
"workflow_id": 123,
136+
"workflow_name": "CI Build and Test",
137+
"total_runs": 200,
138+
"success_count": 150,
139+
"failure_count": 30,
140+
"cancelled_count": 10,
141+
"timed_out_count": 5,
142+
"action_required_count": 5,
143+
"success_rate": 75.0,
144+
"failure_rate": 15.0,
145+
"cancelled_rate": 5.0,
146+
"timed_out_rate": 2.5,
147+
"action_required_rate": 2.5,
148+
"start_time": "2023-09-01T00:00:00Z",
149+
"end_time": "2023-09-30T23:59:59Z"
150+
}
151+
```
152+
153+
## Authentication
154+
155+
### Setting Up OAuth with GitHub
156+
157+
1. **Register a New OAuth Application**
158+
159+
- Go to [GitHub Developer Settings](https://github.com/settings/developers).
160+
- Click on **"New OAuth App"**.
161+
- Fill in the application details:
162+
- **Application Name**
163+
- **Homepage URL**: `http://localhost:8080`
164+
- **Authorization Callback URL**: `http://localhost:8080/callback`
165+
- Obtain your **Client ID** and **Client Secret**.
166+
167+
2. **Configure Application Credentials**
168+
169+
Set your `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` in your environment variables or `config.yaml`.
170+
171+
### Permissions and Scopes
172+
173+
Ensure that your GitHub OAuth application has the necessary scopes:
174+
175+
- `read:user`
176+
- `repo`
177+
- `workflow`
178+
179+
## Testing
180+
181+
### Running Unit Tests
182+
183+
```bash
184+
go test ./tests/unit/...
185+
```
186+
187+
### Running Integration Tests
188+
189+
```bash
190+
go test ./tests/integration/...
191+
```
192+
193+
### Test Coverage
194+
195+
You can generate a test coverage report using:
196+
197+
```bash
198+
go test -coverprofile=coverage.out ./...
199+
go tool cover -html=coverage.out
200+
```
201+
202+
## Contributing
203+
204+
Contributions are welcome! Please follow these steps:
205+
206+
1. **Fork the Repository**
207+
208+
Click on the "Fork" button at the top right of the repository page.
209+
210+
2. **Clone Your Fork**
211+
212+
```bash
213+
git clone https://github.com/yourusername/github-actions-aggregator.git
214+
```
215+
216+
3. **Create a Feature Branch**
217+
218+
```bash
219+
git checkout -b feature/your-feature-name
220+
```
221+
222+
4. **Commit Your Changes**
223+
224+
```bash
225+
git commit -am "Add new feature"
226+
```
227+
228+
5. **Push to Your Fork**
229+
230+
```bash
231+
git push origin feature/your-feature-name
232+
```
233+
234+
6. **Create a Pull Request**
235+
236+
Go to the original repository and open a pull request.
237+
238+
## License
239+
240+
This project is licensed under the [MIT License](LICENSE).
241+
242+
---
243+
244+
**Disclaimer:** This project is not affiliated with GitHub. Ensure compliance with GitHub's [Terms of Service](https://docs.github.com/en/github/site-policy/github-terms-of-service) when using their APIs.

cmd/server/main.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,44 @@ package main
33
import (
44
"log"
55
"os"
6-
"os/signal"
7-
"syscall"
8-
9-
"github.com/mooshe3/github-actions-aggregator/pkg/api"
10-
"github.com/mooshe3/github-actions-aggregator/pkg/config"
11-
"github.com/mooshe3/github-actions-aggregator/pkg/db"
12-
"github.com/mooshe3/github-actions-aggregator/pkg/logger"
13-
"github.com/mooshe3/github-actions-aggregator/pkg/worker"
6+
"os/exec"
7+
8+
"github.com/moosh3/github-actions-aggregator/pkg/api"
9+
"github.com/moosh3/github-actions-aggregator/pkg/config"
10+
"github.com/moosh3/github-actions-aggregator/pkg/db"
11+
"github.com/moosh3/github-actions-aggregator/pkg/github"
12+
"github.com/moosh3/github-actions-aggregator/pkg/logger"
1413
)
1514

1615
func main() {
17-
// Initialize configurations
16+
// Load configuration
1817
cfg := config.LoadConfig()
1918

2019
// Initialize logger
2120
logger.Init(cfg.LogLevel)
2221

22+
// Run migrations
23+
err := runMigrations()
24+
if err != nil {
25+
log.Fatalf("Failed to run migrations: %v", err)
26+
}
27+
2328
// Initialize database
2429
database, err := db.InitDB(cfg)
2530
if err != nil {
2631
log.Fatalf("Failed to connect to database: %v", err)
2732
}
2833

29-
// Start the worker pool
30-
wp := worker.NewWorkerPool(database, 5) // Adjust the number of workers as needed
31-
wp.Start()
34+
// Initialize GitHub client
35+
githubClient := github.NewClient(cfg.GitHub.AccessToken)
3236

3337
// Start the API server
34-
go api.StartServer(cfg, database)
35-
36-
// Wait for interrupt signal to gracefully shut down the worker pool
37-
quit := make(chan os.Signal, 1)
38-
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
39-
<-quit
40-
41-
log.Println("Shutting down worker pool...")
42-
wp.Stop()
38+
api.StartServer(cfg, database, githubClient)
39+
}
4340

44-
log.Println("Server exiting")
41+
func runMigrations() error {
42+
cmd := exec.Command("./scripts/migrate.sh", "up")
43+
cmd.Stdout = os.Stdout
44+
cmd.Stderr = os.Stderr
45+
return cmd.Run()
4546
}

configs/config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server:
2+
port: "8080"
3+
4+
log:
5+
level: "info"
6+
7+
github:
8+
client_id: "your_github_client_id"
9+
client_secret: "your_github_client_secret"
10+
access_token: "your_github_access_token"
11+
webhook_secret: "your_webhook_secret"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS users;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE users (
2+
id SERIAL PRIMARY KEY,
3+
username VARCHAR(255) NOT NULL UNIQUE,
4+
email VARCHAR(255) NOT NULL UNIQUE,
5+
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
6+
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
7+
);

0 commit comments

Comments
 (0)