Is there a way to automatically pull from GitHub?

angelleye

Active Member
Nov 25, 2011
38
2
58
Kansas City, MO
cPanel Access Level
Root Administrator
Twitter
I just recently discovered that Git Version Control is available in cPanel and makes it extremely quick and easy to clone GitHub repos into a directory on the server. This is awesome!

The one thing I'm missing is the ability to automatically pull from GitHub any time changes are made there. Right now I have to do that manually.

Is there any way to setup webhooks with GitHub through cPanel so that changes on GitHub will be automatically pulled into the cPanel repo?

Any information on this would be greatly appreciated. Thanks!
 
  • Like
Reactions: Tarak Nath

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,295
1,272
313
Houston

angelleye

Active Member
Nov 25, 2011
38
2
58
Kansas City, MO
cPanel Access Level
Root Administrator
Twitter
It says this...

Generally, deployment sends finished code into production. You can use different configurations to automatically (push deployment) or manually (pull deployment) deploy changes.
So this seems to be a guide on pushing these repos out to other repos, but what I'm looking is automated pulling of a remote repo (GitHub) into this one.

All I need is for exactly what happens when I manually push the "Update" button to happen automatically.
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,295
1,272
313
Houston

angelleye

Active Member
Nov 25, 2011
38
2
58
Kansas City, MO
cPanel Access Level
Root Administrator
Twitter
Yeah, I found this: github.com/olipo186/Git-Auto-Deploy

We should be able to make it happen this way, but it would sure be a nice feature to have built in. It's so close right now! :)

Does that Update button inside each of the Git repos trigger a particular script that I could hook up to a CRON job?
 
Last edited by a moderator:

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,295
1,272
313
Houston
Hi @angelleye

After speaking with the Product Owner for that team I believe that the specific API function that is being triggered is UAPI Functions - VersionControl::update - Developer Documentation - cPanel Documentation which you should be able to add to a script in for a cron to do what you want.

I also want to encourage you to open a feature request on this, we did have the feature request here Allow users to install websites from version control which included webhooks originally:

Re webhooks - Already planning to provide webhook URLs for repositories which enable deployment! We're intending to offer them on all repositories that enable deployment. If you don't want to use them in to integrate deployments, you can still bookmark them and they'll work all the same.
The comments from cPanelAdamF are super informative on the plan for this in the future as well but if you want to see the functionality in the product we strongly advise a feature request. If you do end up opening it please post the link here so others can vote on it as well.


Thanks!
 

cPanelAdamF

cPanel Product Owner
Staff member
Mar 21, 2013
259
80
153
Houston TX
cPanel Access Level
DataCenter Provider
Twitter
I'll add an important thing to @cPanelLauren's reply: Sending the branch parameter to that Update API call will cause a git pull to occur in order to ensure that it's got the latest from your remote. This is new behavior as of v74.

...and I'll definitely echo @cPanelLauren's guidance to engage with us on a feature request for official webhook support. We were not able to get it done for v74 so we shipped without it. The product management team inside cPanel pays very close attention to that feature request site!
 

Gojko

Well-Known Member
Nov 24, 2014
112
7
68
Macedonia
cPanel Access Level
Root Administrator
Hello, i'm looking how to make this one.
So tried to run cron job:
Code:
/usr/bin/uapi VersionControl update name=test repository_root=/home/user/public_html/test branch=master source_repository='{"remote_name":"origin"}'
and i got:

Code:
---
apiversion: 3
func: update
module: VersionControl
result:
  data:
    available_branches:
      - master
    branch: master
    clone_urls:
      read_only: []

      read_write: []

    deployable: 0
    last_deployment: ~
    last_update:
      author: author <[email protected]>
      date: '1540507571'
      identifier: e6175a616d542c6acf4bce690b7f772911ccb2
      message: Create fff.txt
    name: test
    repository_root: /home/user/public_html/test
    source_repository:
      remote_name: origin
      url: https://github.com/user/test.git
    tasks: []

    type: git
  errors: ~
  messages: ~
  metadata: {}

  status: 1
  warnings: ~
i get the same thing if i use php, cURL login to php and run session url from : UAPI Functions - VersionControl::update - Developer Documentation - cPanel Documentation

response:
Code:
{
    "status":1,
    "messages":null,
    "errors":null,
    "metadata":{},
    "data":{
         "source_repository":  
             {"remote_name":
             
             "origin",
              "url":"https://github.com/user/test.git"
             },
            "deployable":0,
            "name":"test",
            "repository_root":"/home/wuser/public_html/test",
             "available_branches":["master"],
             "clone_urls":
                            {
                             "read_only":[],
                              "read_write":[]
                             },
             "branch":"master",
             "tasks":[],
               "last_update":
                         {
                         "date":"111111",
                         "author":"user <[email protected]>",
                         "message":"Create fff.txt",
                         "identifier":"e6175a616d542c6acf4bce690b7f77291d41c2"
                          },
              "type":"git",
              "last_deployment":null
       },
       "warnings":null
}
 

cPanelAdamF

cPanel Product Owner
Staff member
Mar 21, 2013
259
80
153
Houston TX
cPanel Access Level
DataCenter Provider
Twitter
A question for you before I ask more diagnostic questions:

I see "https://github.com/user/test.git" and "/home/user/public_html/test" as values in the result from your API calls. The github address specifically 404's when I attempt to load it. Can I assume that you've "greeked" these values for privacy reasons and you're not using that as actual values?

The first thing I wanted to check was that the repository the system is attempting to pull from actually exists first before we go too far down other paths of investigation.