Reputation: 558
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)
Upvotes: 1
Views: 1246
Reputation: 558
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:
Upvotes: 0
Reputation: 71
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.
Upvotes: 1
Reputation: 2155
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?
Upvotes: 0