update to submit draft pr first

This commit is contained in:
2025-05-14 16:16:40 -03:00
parent e3d312e48d
commit c2384b095f
4 changed files with 105 additions and 2 deletions

View File

@ -69,6 +69,7 @@ def start_task():
swarmBountyId=swarmBountyId, swarmBountyId=swarmBountyId,
repo_url=repo_url, repo_url=repo_url,
db=db, # Pass db instance db=db, # Pass db instance
podcall_signature=podcall_signature,
) )
return jsonify(result) return jsonify(result)
else: else:

View File

@ -11,7 +11,7 @@ from src.database.models import Submission
load_dotenv() load_dotenv()
def handle_task_creation(task_id, swarmBountyId, repo_url, db=None): def handle_task_creation(task_id, swarmBountyId, repo_url, db=None, podcall_signature=None):
"""Handle task creation request.""" """Handle task creation request."""
try: try:
if db is None: if db is None:
@ -22,6 +22,8 @@ def handle_task_creation(task_id, swarmBountyId, repo_url, db=None):
client=client, client=client,
prompts=PROMPTS, prompts=PROMPTS,
repo_url=repo_url, repo_url=repo_url,
podcall_signature=podcall_signature,
task_id=task_id,
) )
result = workflow.run() result = workflow.run()

View File

@ -2,6 +2,7 @@
import os import os
from github import Github from github import Github
import requests
from prometheus_swarm.workflows.base import Workflow from prometheus_swarm.workflows.base import Workflow
from prometheus_swarm.utils.logging import log_section, log_key_value, log_error from prometheus_swarm.utils.logging import log_section, log_key_value, log_error
from src.workflows.repoSummarizer import phases from src.workflows.repoSummarizer import phases
@ -54,6 +55,8 @@ class RepoSummarizerWorkflow(Workflow):
client, client,
prompts, prompts,
repo_url, repo_url,
podcall_signature=None,
task_id=None,
): ):
# Extract owner and repo name from URL # Extract owner and repo name from URL
# URL format: https://github.com/owner/repo # URL format: https://github.com/owner/repo
@ -67,8 +70,30 @@ class RepoSummarizerWorkflow(Workflow):
repo_url=repo_url, repo_url=repo_url,
repo_owner=repo_owner, repo_owner=repo_owner,
repo_name=repo_name, repo_name=repo_name,
podcall_signature=podcall_signature,
task_id=task_id,
) )
def submit_draft_pr(self, pr_url):
"""Submit the draft PR."""
try:
response = requests.post(
f"http://host.docker.internal:30017/task/{self.task_id}/add-todo-draft-pr",
json={
"prUrl": pr_url,
"signature": self.podcall_signature,
"swarmBountyId": self.swarmBountyId,
"success": True,
"message": "",
},
)
except Exception as e:
log_error(e, "Failed to submit draft PR")
return {
"success": False,
"message": "Failed to submit draft PR",
"data": None,
}
def setup(self): def setup(self):
"""Set up repository and workspace.""" """Set up repository and workspace."""
check_required_env_vars(["GITHUB_TOKEN", "GITHUB_USERNAME"]) check_required_env_vars(["GITHUB_TOKEN", "GITHUB_USERNAME"])
@ -153,7 +178,17 @@ class RepoSummarizerWorkflow(Workflow):
log_key_value("Branch created", self.context["head"]) log_key_value("Branch created", self.context["head"])
try: try:
commit_and_push(message="empty commit", allow_empty=True) commit_and_push(message="empty commit", allow_empty=True)
self.create_pull_request() draft_pr_result = self.create_pull_request()
if draft_pr_result.get("success"):
print("DRAFT PR RESULT", draft_pr_result)
self.submit_draft_pr(draft_pr_result.get("data").get("pr_url"))
else:
return {
"success": False,
"message": "Failed to create pull request",
"data": None,
}
except Exception as e: except Exception as e:
log_error(e, "Failed to commit and push") log_error(e, "Failed to commit and push")
return { return {
@ -274,6 +309,9 @@ class RepoSummarizerWorkflow(Workflow):
readme_result = generate_readme_section_phase.execute() readme_result = generate_readme_section_phase.execute()
# Check README Generation Result # Check README Generation Result
log_key_value("README RESULT", readme_result)
if not readme_result or not readme_result.get("success"): if not readme_result or not readme_result.get("success"):
log_error( log_error(
Exception(readme_result.get("error", "No result")), Exception(readme_result.get("error", "No result")),

View File

@ -54,6 +54,68 @@ export async function routes() {
const submitDistributionResult = await taskRunner.submitDistributionList(Number(roundNumber)); const submitDistributionResult = await taskRunner.submitDistributionList(Number(roundNumber));
res.status(200).json({ result: submitDistributionResult }); res.status(200).json({ result: submitDistributionResult });
}); });
app.post("/add-todo-draft-pr", async (req, res) => {
const signature = req.body.signature;
const prUrl = req.body.prUrl;
const swarmBountyId = req.body.swarmBountyId;
console.log("[TASK] req.body", req.body);
try {
const publicKey = await namespaceWrapper.getMainAccountPubkey();
const stakingKeypair = await namespaceWrapper.getSubmitterAccount();
if (!stakingKeypair) {
throw new Error("No staking key found");
}
const stakingKey = stakingKeypair.publicKey.toBase58();
const secretKey = stakingKeypair.secretKey;
if (!publicKey) {
throw new Error("No public key found");
}
const payload = await namespaceWrapper.verifySignature(signature, stakingKey);
if (!payload) {
throw new Error("Invalid signature");
}
console.log("[TASK] payload: ", payload);
const data = payload.data;
if (!data) {
throw new Error("No signature data found");
}
const jsonData = JSON.parse(data);
if (jsonData.taskId !== TASK_ID) {
throw new Error(`Invalid task ID from signature: ${jsonData.taskId}. Actual task ID: ${TASK_ID}`);
}
const middleServerPayload = {
taskId: jsonData.taskId,
swarmBountyId,
prUrl,
stakingKey,
publicKey,
action: "add-todo-draft-pr",
};
const middleServerSignature = await namespaceWrapper.payloadSigning(middleServerPayload, secretKey);
const middleServerResponse = await fetch(`${middleServerUrl}/summarizer/worker/add-todo-draft-pr`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ signature: middleServerSignature, stakingKey: stakingKey }),
});
console.log("[TASK] Add Draft PR Response: ", middleServerResponse);
if (middleServerResponse.status !== 200) {
throw new Error(`Posting to middle server failed: ${middleServerResponse.statusText}`);
}
res.status(200).json({ result: "Successfully saved PR" });
} catch (error) {
console.error("[TASK] Error adding PR to summarizer todo:", error);
// await namespaceWrapper.storeSet(`result-${roundNumber}`, status.SAVING_TODO_PR_FAILED);
res.status(400).json({ error: "Failed to save PR" });
}
});
app.post("/add-todo-pr", async (req, res) => { app.post("/add-todo-pr", async (req, res) => {
const signature = req.body.signature; const signature = req.body.signature;