add koji call
This commit is contained in:
parent
9c5e3889cb
commit
27b342623a
3 changed files with 59 additions and 5 deletions
|
@ -3,8 +3,53 @@ import hashlib
|
|||
import hmac
|
||||
import logging
|
||||
from flask import Flask, request, abort
|
||||
import koji
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = '123'
|
||||
# koji
|
||||
app.config['KOJI_SERVER'] = 'https://kojidev.stackwebservices.org/kojihub'
|
||||
app.config['KOJI_TARGET'] = 'rl9-candidate'
|
||||
|
||||
app.config['WEBHOOK_SECRET_KEY'] = 'your_secret_key'
|
||||
|
||||
class KojiProcessor:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def koji_build(self, server_url, build_target, source_url):
|
||||
"""
|
||||
Perform a Koji build
|
||||
|
||||
:param server_url: Koji hub server URL
|
||||
:param build_target: Target for the build (e.g., 'f40-candidate')
|
||||
:param source_url: Git repository URL to build from
|
||||
"""
|
||||
# Create a Koji client session
|
||||
session = koji.ClientSession(server_url)
|
||||
|
||||
try:
|
||||
# Authenticate (if required)
|
||||
# Uncomment if authentication is needed
|
||||
session.login()
|
||||
|
||||
# Submit the build task
|
||||
build_id = session.build(
|
||||
source_url, # Source URL
|
||||
build_target, # Build target
|
||||
opts={
|
||||
'scratch': False, # Set to True for scratch build
|
||||
'nowait': False # Wait for build completion
|
||||
}
|
||||
)
|
||||
|
||||
return build_id
|
||||
|
||||
except Exception as e:
|
||||
print(f"Build failed: {e}")
|
||||
return None
|
||||
|
||||
|
||||
class ForgejoWebhookProcessor:
|
||||
def __init__(self, secret_key):
|
||||
|
@ -28,6 +73,7 @@ class ForgejoWebhookProcessor:
|
|||
# Extract key webhook information
|
||||
repository = data.get('repository', {})
|
||||
commits = data.get('commits', [])
|
||||
head_commit = data.get('head_commit')
|
||||
ref = data.get('ref', '')
|
||||
|
||||
# Log basic webhook details
|
||||
|
@ -36,9 +82,16 @@ class ForgejoWebhookProcessor:
|
|||
logging.info(f"Number of Commits: {len(commits)}")
|
||||
|
||||
# Custom processing logic here
|
||||
for commit in commits:
|
||||
logging.info(f"Commit: {commit.get('id')}")
|
||||
logging.info(f"Message: {commit.get('message')}")
|
||||
# for commit in commits:
|
||||
# logging.info(f"Commit: {commit.get('id')}")
|
||||
# logging.info(f"Message: {commit.get('message')}")
|
||||
|
||||
commit_id = head_commit.get("id")
|
||||
clone_url = repository.get("clone_url")
|
||||
|
||||
git_url = f"git+{clone_url}#{commit_id}"
|
||||
|
||||
KojiProcessor().koji_build(app.config['KOJI_SERVER'], app.config['KOJI_TARGET'], git_url)
|
||||
|
||||
except json.JSONDecodeError:
|
||||
logging.error("Invalid JSON payload")
|
||||
|
@ -47,7 +100,7 @@ class ForgejoWebhookProcessor:
|
|||
|
||||
@app.route('/forgejo-webhook', methods=['POST'])
|
||||
def webhook():
|
||||
processor = ForgejoWebhookProcessor('your_secret_key')
|
||||
processor = ForgejoWebhookProcessor(app.config['WEBHOOK_SECRET_KEY'])
|
||||
|
||||
# Get payload and signature
|
||||
payload = request.get_data(as_text=True)
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
flask
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
flask
|
||||
koji
|
Loading…
Add table
Reference in a new issue