repman icon indicating copy to clipboard operation
repman copied to clipboard

[Feature request] Mass webhook synchronization

Open Szpadel opened this issue 4 years ago • 8 comments

Currently only way to synchronize package is via webhook

When packages are created by user without right permissions, packages are created but they will not have webhook set up, and they will not be refreshed automatically.

Solutions would be to add possibility to refresh synchronisation of all webhooks in organization. (Doing this one by one is usually not an option)

Szpadel avatar Feb 04 '21 10:02 Szpadel

I think it relates to https://github.com/repman-io/repman/issues/122

zlodes avatar Feb 04 '21 12:02 zlodes

I think the OP means that it would be great if there could be just one hook for the whole organization, so that when it receives a POST with repository data it will update that repository inside the organization. Here's an example of that hook. This works with packeton but packeton is outdated and repman is easier to update to use composer 2, for me:

Organization webhook

Right now I have to add each hook for each package. It would be nice if it can be done for the whole organization. Thanks for looking into it.

shemgp avatar Aug 25 '21 03:08 shemgp

Currently you can synchronize webhook using "Webhook" page (for given package): Screenshot from 2021-08-25 08-09-07

An organization wide webhook and repository discovery will be more difficult to do as each provider sends data in a different form.

Another thing that comes to my mind: you could do an action that synchronizes webhooks for the entire organization - something like that is relatively easy to do (just like above button but with forech :wink:).

akondas avatar Aug 25 '21 06:08 akondas

Yes please. Please add the feature that synchronizes webhooks for the entire organization. Then, later, I think, it would be easy enough, for me, to add hooks for each provider, probably depending on the URL, so it can parse the POST to determine the repository to update.

shemgp avatar Aug 26 '21 00:08 shemgp

Proof of concept for OrganizationController.php:

    /**
     * @Route("/organization/{organization}/{token}/webhook", name="organization_webhook", methods={"GET","POST"}, requirements={"organization"="%organization_pattern%"})
     */
    public function organizationWebhook(Organization $organization, string $token, Request $request): Response
    {
        $validToken = $this->organizationQuery->findToken($organization->id(), $token)
            ->getOrNull();
        if ($validToken)
        {
            if ($request->isMethod(Request::METHOD_POST))
            {
                $input = json_decode($request->getContent(), true);
                // do matching here depending on host that posts?
                if (isset($input['repository']['full_name']))
                {
                    $packageNames = $this->packageQuery->getAllNames($organization->id());
                    $package = null;
                    foreach($packageNames as $searchPackage)
                        if ($searchPackage->name() == $input['repository']['full_name'])
                        {
                            $package = $searchPackage;
                            break;
                        }
                    if ($package)
                    {
                        $this->dispatchMessage(new SynchronizePackage($package->id()));
                        $this->addFlash('success', sprintf('Package "%s" will be synchronized in background.', $package->name()));
                    }
                }
            }
        }
        else
            $this->addFlash('error', sprintf('Invalid token for %s.', $organization->name()));
        return $this->redirectToRoute('organization_tokens', ['organization' => $organization->alias()]);
    }

shemgp avatar Aug 26 '21 15:08 shemgp

@shemgp would a console command also suffice?

xvilo avatar Jan 09 '22 08:01 xvilo

@xvilo It would be better as a web hook for my use case. I'm using Gitea and it's web hook in organization feature so that I don't have to add all the web hooks to each repo under that organization. So far, my fork of repman, with patches, works for my me.

shemgp avatar Jan 09 '22 12:01 shemgp

We need this kind of feature too. We are working to migrate around 500 libraries from toran to repman. We use Bitbucket server to manage git repos, and there is no way for automatic setting these webhooks. I was thinking that besides a general webhook for an organisation, it will be great to have the possiblity to set some kind of json path with the json key that stores the actual repo location. This way it will be easier to identify the update package instead of going trough all of them.

beniamin avatar Feb 17 '22 09:02 beniamin