1

I am developing an app that would detect that something was merged in specific branch and take some actions based on that. In order to solve my problem I need to find the name of a branch that was merged to the branch I monitor.

Let's say GitHub sends me "everything" and my script must react when "some-branch" is merged to branch "Tests". Also my script must be able to detect the name of merged branch (in this case "some-branch").

Only solution I found so far - is to read property "message" of every commit in array "commits" and parse it. They are pretty tipical: "Merge branch 'some-branch' into Tests".

There are two problems

  • Message theoretically could be modified by user (for example SourceTree shows you editor after conflict resolve)
  • In case of Fast-Forward there is no message

What could you advise, how can I detect fact of merge and the name of merged branch better?

Thanks!

2 Answers 2

3

Only if the branch merge is via pull request on github, then you can detect the event or relate things, such as pull_request_review event.

And for the command to view branches merged into Tests branch is git branch --merged Tests.

Sign up to request clarification or add additional context in comments.

Comments

2

I'm afraid due to the protocol of git, this is not always possible.

  1. In fast-forward case, no new blobs are created, but only blobs are transferred to github.

  2. If a merge commit exists, as you already realized, the commit message may be overridden by user.

I guess the best we can do is to monitor a branch, and consider in terms of push instead of merge.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.