Hi, I was wondering if it was possible to get the source branch after a merge has successfully completed. I want to deploy a website on Kubernetes and deploy an instance of that website named after the branch. So for example, I’ll have a branch named “feature” and then that will deploy on “feature(dot)example(dot)com” and my main branch will then always sync with “staging(dot)example(dot)com” until I promote that, at which point it will become “example(dot)com”
Now I want to make sure that after my branch has been merged into main, the old feature branch’s running instance gets deleted, but I found no obvious way of doing that without also knowing where the merge came from. I know that a “push” event happens at the target branch when you merge into it, but there doesn’t seem to be an obvious way to get the source branch from that. Any ideas?
I am going to answer this in the context of GitHub, but this largely applies to other vendors. When a pull request is merged into a branch it triggers a push event which sends a webhook to Drone, which in turn triggers a pipeline execution. The webhook payload for a push event (example found here) does not include any information on where the push came from (meaning we don’t know if it was merged froma pull request, or from which branch it descended). Since this information is not provided to Drone, it has no way of knowing this information. So unfortunately I am not aware of any out-of-the-box options. With that being said, you may be able to use the GitHub API to write some custom code that you execute as part of your pipeline to figure out the source branch.
Ah, okay that makes sense. I guess I’ll look for other ways of getting what I want, if there are not really any other options. Maybe I am just overlooking something.