Skip to content
This repository was archived by the owner on Mar 15, 2026. It is now read-only.

Commit ba4939f

Browse files
feat: upsert ProductConfig by name instead of always creating a new one
When the YAML name matches an existing ProductConfig for the same organization, update github_url, cursor_agent_api_key, and github_token instead of inserting a duplicate row. Also includes CS Fixer auto-fixes.
1 parent b4fcd89 commit ba4939f

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

src/PlanningAgent/Infrastructure/Handler/PlanIssueHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private function handleFeedbackNeeded(string $text, string $githubUrl, string $g
248248
private function handlePlanProduced(string $text, string $githubUrl, string $githubToken, int $issueNumber): void
249249
{
250250
$reviewNotice = "\n\n---\n"
251-
. "**Review this plan.** Add comments to refine it, or add the `prdb:plan-approved` "
251+
. '**Review this plan.** Add comments to refine it, or add the `prdb:plan-approved` '
252252
. 'label to start implementation.';
253253

254254
$this->githubIntegrationFacade->postIssueComment(

src/ProductConfig/Domain/Command/CreateProductConfigCommand.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,31 @@ public function execute(
116116
$accountId = $this->resolveOrCreateAccountId($email, $password, $output);
117117
$organizationId = $this->resolveOrCreateOwnedOrganizationId($accountId, $output);
118118

119-
$productConfig = new ProductConfig(
120-
$organizationId,
121-
$name,
122-
$githubUrl,
123-
$cursorAgentApiKey,
124-
$githubToken
125-
);
119+
$storedName = mb_substr($name, 0, 256);
120+
$productConfig = $this->entityManager
121+
->getRepository(ProductConfig::class)
122+
->findOneBy([
123+
'organizationId' => $organizationId,
124+
'name' => $storedName,
125+
]);
126+
127+
if ($productConfig instanceof ProductConfig) {
128+
$productConfig->setGithubUrl($githubUrl);
129+
$productConfig->setCursorAgentApiKey($cursorAgentApiKey);
130+
$productConfig->setGithubToken($githubToken);
131+
$output->writeln(sprintf('<info>Existing ProductConfig "%s" found, updating.</info>', $name));
132+
} else {
133+
$productConfig = new ProductConfig(
134+
$organizationId,
135+
$name,
136+
$githubUrl,
137+
$cursorAgentApiKey,
138+
$githubToken
139+
);
140+
$this->entityManager->persist($productConfig);
141+
$output->writeln(sprintf('<info>Creating new ProductConfig "%s".</info>', $name));
142+
}
126143

127-
$this->entityManager->persist($productConfig);
128144
$this->entityManager->flush();
129145
} catch (Throwable $e) {
130146
$output->writeln(sprintf('<error>Failed to create product config: %s</error>', $e->getMessage()));

src/ProductConfig/Domain/Entity/ProductConfig.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public function getGithubUrl(): string
7777
return $this->githubUrl;
7878
}
7979

80+
public function setGithubUrl(string $githubUrl): void
81+
{
82+
$this->githubUrl = mb_substr(trim($githubUrl), 0, 2048);
83+
}
84+
8085
#[ORM\Column(
8186
name: 'cursor_agent_api_key',
8287
type: Types::STRING,
@@ -90,6 +95,11 @@ public function getCursorAgentApiKey(): string
9095
return $this->cursorAgentApiKey;
9196
}
9297

98+
public function setCursorAgentApiKey(string $cursorAgentApiKey): void
99+
{
100+
$this->cursorAgentApiKey = mb_substr(trim($cursorAgentApiKey), 0, 2048);
101+
}
102+
93103
#[ORM\Column(
94104
name: 'github_token',
95105
type: Types::STRING,
@@ -102,4 +112,9 @@ public function getGithubToken(): string
102112
{
103113
return $this->githubToken;
104114
}
115+
116+
public function setGithubToken(string $githubToken): void
117+
{
118+
$this->githubToken = mb_substr(trim($githubToken), 0, 2048);
119+
}
105120
}

src/TeamleaderAgent/Infrastructure/Handler/ProcessProductConfigHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private function revisePlan(string $githubUrl, string $githubToken, string $prod
205205

206206
if (!$this->hasNonBotCommentNewerThan($comments, $planningDoneAt, $botLogin)) {
207207
$this->logger->info('[Teamleader] No human feedback after planning-done label, awaiting review', [
208-
'issueNumber' => $issueNumber,
208+
'issueNumber' => $issueNumber,
209209
'planningDoneAt' => $planningDoneAt->format('c'),
210210
]);
211211

0 commit comments

Comments
 (0)