Skip to content

Commit 1e94c46

Browse files
committed
Initial version of the github agent (just workflow)
0 parents  commit 1e94c46

File tree

3 files changed

+289
-0
lines changed

3 files changed

+289
-0
lines changed

.github/workflows/doc-update.yml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: Documentation Update
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
test_repo:
7+
description: 'Repository URL to test with'
8+
required: false
9+
default: 'https://github.com/CodeBoarding/insights-core'
10+
type: string
11+
schedule:
12+
# Run daily at 2 AM UTC
13+
- cron: '0 2 * * *'
14+
15+
jobs:
16+
update-docs:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
with:
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Get repository URL
29+
id: repo-url
30+
run: |
31+
# Use test repository if provided via workflow_dispatch, otherwise use current repo
32+
if [ "${{ github.event.inputs.test_repo }}" != "" ]; then
33+
REPO_URL="${{ github.event.inputs.test_repo }}"
34+
echo "Using test repository: $REPO_URL"
35+
else
36+
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
37+
echo "Using current repository: $REPO_URL"
38+
fi
39+
echo "repo_url=$REPO_URL" >> $GITHUB_OUTPUT
40+
41+
- name: Fetch documentation files
42+
id: fetch-docs
43+
run: |
44+
# Replace this with your actual endpoint URL
45+
ENDPOINT_URL="${{ vars.CODEBOARDING_ENDPOINT || 'http://0.0.0.0:8000/generate_docs' }}"
46+
REPO_URL="${{ steps.repo-url.outputs.repo_url }}"
47+
48+
echo "Fetching documentation from: $ENDPOINT_URL?url=$REPO_URL"
49+
50+
# Make the API call and save response
51+
response=$(curl -s -w "%{http_code}" -o response.json "$ENDPOINT_URL?url=$REPO_URL")
52+
http_code=${response: -3}
53+
54+
if [ "$http_code" != "200" ]; then
55+
echo "Error: API call failed with status code $http_code"
56+
cat response.json
57+
exit 1
58+
fi
59+
60+
# Check if response is valid JSON
61+
if ! jq empty response.json 2>/dev/null; then
62+
echo "Error: Invalid JSON response"
63+
cat response.json
64+
exit 1
65+
fi
66+
67+
echo "API call successful"
68+
echo "Response JSON contents:"
69+
cat response.json
70+
71+
- name: Create .codeboarding directory and files
72+
run: |
73+
# Create the .codeboarding directory
74+
mkdir -p .codeboarding
75+
76+
# Debug: Print response.json structure and keys
77+
echo "=== JSON DEBUGGING ==="
78+
echo "Response JSON structure:"
79+
jq . response.json
80+
81+
echo "Top-level keys in response:"
82+
jq 'keys' response.json
83+
84+
echo "Checking if 'files' key exists:"
85+
jq 'has("files")' response.json
86+
87+
echo "If files exists, what type is it:"
88+
jq 'if has("files") then (.files | type) else "files key not found" end' response.json
89+
90+
echo "If files exists, what are its keys:"
91+
jq 'if has("files") then (.files | keys) else "files key not found" end' response.json
92+
echo "=== END JSON DEBUGGING ==="
93+
94+
# Parse JSON response and create files using keys as filenames
95+
if jq -e '.files' response.json > /dev/null; then
96+
echo "Files key found, proceeding to create files..."
97+
98+
# Get each key from files object and create a file with that name
99+
jq -r '.files | keys[]' response.json | while read -r filename; do
100+
echo "Processing file: $filename"
101+
102+
# Get the content for this filename
103+
content=$(jq -r ".files[\"$filename\"]" response.json)
104+
105+
# Add .md extension if not present
106+
if [[ "$filename" != *.md ]]; then
107+
output_filename="${filename}.md"
108+
else
109+
output_filename="$filename"
110+
fi
111+
112+
# Write content to file
113+
echo "$content" > ".codeboarding/$output_filename"
114+
echo "Created file: .codeboarding/$output_filename"
115+
done
116+
else
117+
echo "No 'files' key found in response JSON"
118+
fi
119+
120+
# List created files
121+
echo "Files created in .codeboarding:"
122+
ls -la .codeboarding/
123+
124+
# Show a sample of file contents for debugging
125+
echo "Sample file contents:"
126+
for file in .codeboarding/*.md; do
127+
if [ -f "$file" ]; then
128+
echo "=== Contents of $file (first 10 lines) ==="
129+
head -10 "$file"
130+
echo "=== End of $file sample ==="
131+
break
132+
fi
133+
done
134+
135+
- name: Check for changes
136+
id: changes
137+
run: |
138+
# Add .codeboarding to git to check for changes
139+
git add .codeboarding/
140+
141+
# Check if there are any changes
142+
if git diff --cached --quiet; then
143+
echo "has_changes=false" >> $GITHUB_OUTPUT
144+
echo "No changes detected"
145+
else
146+
echo "has_changes=true" >> $GITHUB_OUTPUT
147+
echo "Changes detected"
148+
git diff --cached --name-status
149+
fi
150+
151+
- name: Create Pull Request
152+
if: steps.changes.outputs.has_changes == 'true'
153+
uses: peter-evans/create-pull-request@v5
154+
with:
155+
token: ${{ secrets.GITHUB_TOKEN }}
156+
commit-message: "docs: update codeboarding documentation"
157+
title: "doc update"
158+
body: |
159+
## Documentation Update
160+
161+
This PR contains updated documentation files fetched from the codeboarding service.
162+
163+
### Changes
164+
- Updated files in `.codeboarding/` directory
165+
- Files fetched from: ${{ vars.CODEBOARDING_ENDPOINT || 'codeboarding endpoint' }}
166+
- Repository: ${{ steps.repo-url.outputs.repo_url }}
167+
168+
This PR was automatically generated by the documentation update workflow.
169+
branch: docs/codeboarding-update
170+
base: main
171+
delete-branch: true
172+
173+
# - name: Cleanup
174+
# if: success()
175+
# run: |
176+
# rm -f response.json

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test files
2+
test_response.json
3+
test_codeboarding/
4+
5+
# Environment files
6+
.env
7+
8+
# Logs
9+
*.log
10+
11+
# OS generated files
12+
.DS_Store
13+
.DS_Store?
14+
._*
15+
.Spotlight-V100
16+
.Trashes
17+
ehthumbs.db
18+
Thumbs.db

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# CodeBoarding GitHub Action
2+
3+
This repository contains a GitHub Action that automatically fetches documentation files from a codeboarding service and creates pull requests with the updated content.
4+
5+
## How it works
6+
7+
1. The action gets the current repository URL
8+
2. Calls your endpoint with the repository URL as a query parameter
9+
3. Receives a JSON response with files and their content
10+
4. Creates/updates files in the `.codeboarding` directory with `.md` extension
11+
5. Creates a pull request with the changes (if any)
12+
13+
## Setup
14+
15+
### 1. Configure the endpoint URL
16+
17+
You have two options to configure the endpoint URL:
18+
19+
**Option A: Using repository variables (recommended)**
20+
1. Go to your repository Settings > Secrets and variables > Actions
21+
2. In the "Variables" tab, create a new variable:
22+
- Name: `CODEBOARDING_ENDPOINT`
23+
- Value: `https://your-api-endpoint.com/docs` (replace with your actual endpoint)
24+
25+
**Option B: Edit the workflow file**
26+
Replace the line in `.github/workflows/doc-update.yml`:
27+
```yaml
28+
ENDPOINT_URL="${{ vars.CODEBOARDING_ENDPOINT || 'https://your-api-endpoint.com/docs' }}"
29+
```
30+
31+
### 2. Expected API Response Format
32+
33+
Your endpoint should return a JSON response in this format:
34+
35+
```json
36+
{
37+
"repository": "owner/repo-name",
38+
"files": {
39+
"getting-started": "# Getting Started\n\nThis is the content...",
40+
"api-reference": "# API Reference\n\nAPI documentation...",
41+
"troubleshooting": "# Troubleshooting\n\nCommon issues..."
42+
}
43+
}
44+
```
45+
46+
- `repository`: The repository name (informational)
47+
- `files`: A dictionary where keys are filenames and values are the markdown content
48+
49+
### 3. Permissions
50+
51+
The workflow requires the following permissions (already configured):
52+
- `contents: write` - to create commits
53+
- `pull-requests: write` - to create pull requests
54+
55+
## Usage
56+
57+
### Automatic execution
58+
- The action runs daily at 2 AM UTC
59+
- Scheduled runs can be configured by modifying the cron expression in the workflow
60+
61+
### Manual execution
62+
1. Go to Actions tab in your repository
63+
2. Select "Documentation Update" workflow
64+
3. Click "Run workflow"
65+
66+
## File handling
67+
68+
- Files are created in the `.codeboarding` directory
69+
- All files automatically get `.md` extension if not already present
70+
- Existing files are overwritten with new content
71+
- Only creates a PR if there are actual changes
72+
73+
## Pull Request behavior
74+
75+
- PR title: "doc update"
76+
- Branch name: `docs/codeboarding-update`
77+
- Automatically deletes the branch after PR is merged/closed
78+
- Only creates PR if there are changes to commit
79+
80+
## Troubleshooting
81+
82+
### API call fails
83+
- Check that your endpoint URL is correct
84+
- Verify the endpoint is accessible from GitHub Actions runners
85+
- Check the Actions logs for the exact error message
86+
87+
### No PR created
88+
- This means no changes were detected
89+
- The API response might be identical to existing files
90+
- Check the "Check for changes" step in the workflow logs
91+
92+
### Invalid JSON response
93+
- Verify your endpoint returns valid JSON
94+
- Check the response format matches the expected structure
95+
- Review the API response in the workflow logs

0 commit comments

Comments
 (0)