-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration-request-handler.yml
More file actions
143 lines (119 loc) · 5.22 KB
/
integration-request-handler.yml
File metadata and controls
143 lines (119 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Integration Request Handler
on:
issues:
types: [opened, edited]
permissions:
contents: write
pull-requests: write
issues: write
jobs:
handle-integration-request:
runs-on: ubuntu-latest
if: |
github.event.issue.labels[0].name == 'integration' ||
contains(github.event.issue.title, '[Integration Request]') ||
contains(github.event.issue.title, 'Integration Request')
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install Dependencies
run: |
pip install PyGithub requests pyyaml
- name: Fetch Integration Generator Script
run: |
mkdir -p .github/scripts
curl -o .github/scripts/generate_integration.py \
https://raw.githubusercontent.com/faneX-ID/core/main/.github/scripts/generate_integration.py
- name: Parse Issue and Generate Integration
id: generate
run: |
python << 'EOF'
import json
import sys
import os
from pathlib import Path
sys.path.insert(0, '.github/scripts')
from generate_integration import IntegrationGenerator, parse_issue_body
# Get issue body
issue_body = """${{ github.event.issue.body }}"""
# Parse issue data
issue_data = parse_issue_body(issue_body)
issue_data['issue_number'] = ${{ github.event.issue.number }}
issue_data['issue_title'] = "${{ github.event.issue.title }}"
if not issue_data.get('integration-name'):
print("❌ Integration name not found in issue")
sys.exit(1)
# Generate integration files
versions_url = "https://raw.githubusercontent.com/faneX-ID/core/main/.github/versions.json"
generator = IntegrationGenerator(issue_data, versions_url)
files = generator.generate_all()
# Save files
output_dir = Path("generated_integration")
output_dir.mkdir(exist_ok=True)
domain = generator.generate_domain(issue_data.get('integration-name', 'new_integration'))
integration_dir = output_dir / domain
integration_dir.mkdir(exist_ok=True)
(integration_dir / "manifest.json").write_text(files['manifest.json'])
(integration_dir / "integration.py").write_text(files['integration.py'])
(integration_dir / "README.md").write_text(files['README.md'])
# Output metadata
with open('.github/integration_metadata.json', 'w') as f:
json.dump({
'domain': domain,
'complexity': files['complexity'],
'can_auto_generate': files['can_auto_generate'],
'integration_name': issue_data.get('integration-name')
}, f)
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"domain={domain}\n")
f.write(f"complexity={files['complexity']}\n")
f.write(f"can_auto={str(files['can_auto_generate']).lower()}\n")
f.write(f"integration_name={issue_data.get('integration-name')}\n")
EOF
env:
GITHUB_OUTPUT: ${{ github.output }}
- name: Comment on Issue
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const metadataPath = '.github/integration_metadata.json';
let comment = '## 🤖 Example Integration Generation Status\n\n';
if (fs.existsSync(metadataPath)) {
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf8'));
comment += `**Integration:** ${metadata.integration_name}\n`;
comment += `**Domain:** \`${metadata.domain}\`\n\n`;
comment += '✅ **Example integration files generated!**\n\n';
comment += 'I will create a pull request with the example integration files.';
} else {
comment += '❌ Could not generate integration files.';
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: feature/example-integration-${{ steps.generate.outputs.domain }}
title: "feat: Add ${{ steps.generate.outputs.integration_name }} example integration"
body: |
This PR adds the **${{ steps.generate.outputs.integration_name }}** example integration.
📋 **Generated from Issue #${{ github.event.issue.number }}**
Related to #${{ github.event.issue.number }}
commit-message: "feat: add ${{ steps.generate.outputs.integration_name }} example integration (from #${{ github.event.issue.number }})"
path: generated_integration
delete-branch: true
labels: |
integration
example