pythongithubwebhooksredmine-apiweb-scripting

How to run a script after a pull-request on GitHub?


Good morning, everyone,

I want to create a script which automatically update an issue on RedMine when someone make a pull-request on our GitHub based on the pull-request comment.

I wrote a script in Python using selenium and redmine REST API that retrieves the comment of a pull-request on GitHub made by its requester, but I have to execute it manually.
Do you know if it is possible to execute a python script automatically just after a pull request?

(Currently the script is stored on my computer, but ideally it will be stored on an external server so that I and my partners can use it more easily)

I have searched some solutions based on WebHooks or CRON, but nothing seems to answer my problem.

I am using Python 2.7

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

import test


# Xpath to retrieve number of the fix
DISCONNECTED_XPATH = "//div[4]/div/main/div[2]/div[1]/div/div[2]/div[3]/div[2]/div[1]/div[1]/div[2]/div/div[2]/task-lists/table/tbody/tr/td/p"
CONNECTED_XPATH =    "//div[4]/div/main/div[2]/div[1]/div/div[1]/div[3]/div[2]/div[1]/div[1]/div[2]/div/div[2]/task-lists/table/tbody/tr/td/p"
PULL_URL = "https://github.com/MaxTeiger/TestCoopengo/pull/1"

# Init
print("Opening the browser...")
driver = webdriver.Firefox()
# Go to the specified pull 
print("Reaching " + PULL_URL)
driver.get(PULL_URL)

assert "GitHub" in driver.title

print("Finding the pull comment...")
# retrieve the fix id 
elem = driver.find_element_by_xpath(DISCONNECTED_XPATH)
issueID = elem.text

print("Closing driver")
driver.close()

issueID = int(issueID.split('#')[1])
print("Issue ID : " +str(issueID))

print("Updating ticket on RedMine...")
test.updateIssueOnRedMineFromGit(issueID, PULL_URL)

Thank you if you can help me or if you have a better solution to my problem


Solution

  • I finally found an answer to my problem and it turns out that the webhooks proposed by GitHub answer my problem (Repo > Settings > Webhooks).

    Now, I just need to set up a server that calls my script when I make an HTML Post request, but I don't know how to retrieve the URL of the wanted pull-request.