简体   繁体   中英

Java monitor GitHub repository

I want to create a Java application that monitors a GitHub repository, pulls changes to the machine it is running on and triggers a method when something in the repo has changed.

while(true)
{
    if(new commits on the remote github repo)
    {
        pullChanges();
        doSomething();
    }
}

I am currently using JGit and regularly deleting the local repository to clone a new one and compare the combined file size to check if anything has changed. This is incredibly hacky and not reliable (if a commit just changes a letter, the file sizes would be the same)

Your method to get a diff between your local copy and the remote is too tricky to be reliable.

See this post: How to check for changes on remote (origin) Git repository?

You can use GitHub Webhooks .

Webhooks allow you to build or set up integrations which subscribe to certain events on GitHub.com. When one of those events is triggered, we'll send a HTTP POST payload to the webhook's configured URL. Webhooks can be used to update an external issue tracker, trigger CI builds, update a backup mirror, or even deploy to your production server. You're only limited by your imagination.

I changed it to clone the repository when the java application starts, after that I created a seperate thread that pulls new commits from the repository every 30 seconds and checks if something has changed with the 'FetchResult' returned from the Java method.

These helped me:

Cloning a repo

Pulling commits

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM