Skip to content

Commit

Permalink
Merge pull request vtsykun#161 from vtsykun/fix/bitbucket-sync
Browse files Browse the repository at this point in the history
Fix bitbucket oauth2 package sync
  • Loading branch information
vtsykun authored Sep 2, 2023
2 parents 224ad41 + f881026 commit 0f2dd8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/Integrations/Base/AppIntegrationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected function pushEventSynchronize(App $app, array $payload): ?array
return false;
}

if ($pkg = $repo->findOneByName($name)) {
if ($pkg = $repo->findOneByName(strtolower($name))) {
foreach (($payload['urls'] ?? []) as $url) {
if ($url && $pkg->getRepository() === $url) {
$pkg->setExternalRef($payload['external_ref']);
Expand Down Expand Up @@ -239,13 +239,20 @@ protected function pushEventSynchronize(App $app, array $payload): ?array
}

$job = null;
$this->getCached($app, "sync:{$payload['name']}", false === $newAdded, function (CacheItem $item) use ($payload, $app, &$job) {
$item->expiresAfter(86400);
$this->getCached($app, "sync:{$payload['name']}", false === $newAdded, function (CacheItem $item) use ($payload, $useCache, $app, &$job) {
$item->expiresAfter($useCache ? 86400 : 40);
$job = $this->scheduler->publish('integration:repo:sync', ['external_id' => $payload['external_ref'], 'app' => $app->getId()], $app->getId());
$job = ['status' => 'new_repo', 'job' => $job->getId(), 'code' => 202];
return [];
});

if ($job !== null && ($pkg = PacketonUtils::findPackagesByPayload($payload, $repo))) {
$job2 = $this->scheduler->scheduleUpdate($pkg);
$jobs = array_values(array_filter([$job['job'] ?? null, $job2->getId()]));
$status = implode(',', array_filter([$job['status'] ?? null, 'success']));
return ['status' => $status, 'code' => 202, 'job' => $jobs];
}

return $job;
}

Expand Down
11 changes: 9 additions & 2 deletions src/Integrations/RemoteReposSyncWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public function __invoke(Job $job): array

$package->setExternalRef($payload['external_id']);
$package->setRepository($url);
$package->setIntegration($app);
$package->setRepoType(RepTypes::INTEGRATION);
$package->setAutoUpdated(true);

if (AppUtils::clonePref($client->getConfig(), $app) === 'clone_ssh') {
$package->setRepoType(RepTypes::VCS);
} else {
$package->setIntegration($app);
$package->setRepoType(RepTypes::INTEGRATION);
}

$this->packageManager->updatePackageUrl($package);
$errors = $this->validator->validate($package, null, ['Create']);
Expand All @@ -73,6 +79,7 @@ public function __invoke(Job $job): array

$this->packageManager->insetPackage($package);
$this->scheduler->scheduleUpdate($package);

return [
'status' => Job::STATUS_COMPLETED,
'message' => "A new package {$package->getName()} was created successfully",
Expand Down

0 comments on commit 0f2dd8b

Please sign in to comment.