GitHub Integration using Java GitHub
tutorials → integrations → GitHub Integration using Java
- Activity Streams
- Android Chat App
- Coffee Order System
- Collaborative Post-It Board
- IoT Light Sensor
- Music Collection
- Pizza Delivery Tracker
- Realtime Cart
- Realtime Chat in Browser
- Comment Feed using Vue
- Realtime Flight Tracker
- Realtime Todo List
- Android
- Angular 2
- AngularJS
- C++
- HTTP
- Ionic 2
- Java
- JavaScript
- Node
- Preact
- React
- React Native
- Swift
- VueJS
- Authentication
- Email Auth
- HTTP Webhook Auth
- Open Auth
- Features
- Events
- Remote Procedure Calls
- General
- Handling Data Conflicts
- Security Overview
- Permissioning
- User-specific data
- Valve advanced
- Valve Realtime
- Valve simple
- Realtime Database
- Anonymous Records
- Lists
- Records
- AWS Lambda
- AWS SNS
- GitHub
- Mailchimp
- Nexmo
- Pusher
- Sendgrid
- Slack
- Twilio
- WebRTC
- WebRTC 03: Audio & Video
- WebRTC 01: Data Channels
- WebRTC 06: File Transfer
- WebRTC 02: Full Mesh
- WebRTC: in production
- WebRTC: Fundamentals & Concepts
- WebRTC 06: Screen Sharing
- WebRTC 05: Video Manipulation
- Realtime Database
- Modelling relational data
- Realtime Events
- Live Progress Bar
In this post, we'll be building a simple GitHub issue tracker similar to waffle.io. It will show active issues on a project with specific workflow labels, and it will update in real time as issues are created and updated on GitHub.
This post will focus on building a connector using deepstream's Java API and Kohsuke Kawaguchi's GitHub API for Java. I will assume a basic understanding of Java. If you haven't already, take a look at Getting Started with Java. For brevity, we won't cover how to build the React.js frontend, but feel free to take a look at the one provided. If you'd like to read more about integrating deepstream with React.js, read getting started with React.
Setting Up
If you'd like to follow along, you can clone the completed project on GitHub.
Create a free account and get your API key
Create an application through the deepstreamHub dashboard, and make a note of the corresponding application url.
Within the client directory, run npm install to install the client dependencies, then run python -m SimpleHTTPServer to start a test server. You should then be able to view the client at localhost:8000.
Create a GitHub personal access token with repository access. Then create a file
It's also possible to put your GitHub credentials in this file to avoid this step — see here.
I recommend setting up a test GitHub repository with some issues, and labeling some of them with 'roadmap', 'ready', 'in progress', 'awaiting review', or 'in review'. It's also a good idea to give those labels some nice colors — we'll be using those later on.
Install ngrok which will allow us to listen for external connections from the webhook we'll use later on. Start it using ngrok http 8080 , and make note of the forwarding address.
We're using Gradle to manage dependencies.
Project Setup
In our main method, we set the details of our local deepstream server, the webhook URI given when you start ngrok, and the GitHub repository that we're getting our issues from.
You'll need to update the WEBHOOK_URI , DEEPSTREAM_URI and GITHUB_REPO environment variables in your build system to get the connector to run locally.
Setting up API Objects
We first setup a connection to our deepstream client.
. then setup a connection to GitHub.
Initial State
Our connector will need to fetch any open issues from GitHub's API and create corresponding records in deepstream for rendering in the client.
Interesting Labels
We only care about certain labels, so we'll create a list of these and add them to a deepstream list.
Issue Lists
Now we can start inserting issues into lists based on which labels they have.
In our initializeIssueLists() method, we make deepstream lists for each of the labels and ensure that they're empty.
We get a list of open issues from GitHub.
Then we add each issue to all the lists for each label it has.
However, we're only interested in some of the labels. We also want to create a record with our issue id to store the issue data.
We call this method from the constructor.
Coloring Labels
GitHub allows each label to have a color, so we get that from the API and pass it to the client for rendering.
Inside our setupIssueColors method, we simply create a deepstream record that maps label names to hex colors.
Realtime Updates
We use the GitHub webhook API to receive updates when issues are modified.
Event Listener
First, we start a server to listen for webhook events.
Our startServer() method instantiates the RequestHandler, which we'll describe shortly.
Subscribe to Issue Events
So that we are notified when the issues are modified, we subscribe through the GitHub webhook API, specifying GHEvent.ISSUES , as this is the only event we're interested in.
Handling Events
Events are handled in the RequestHandler.handle() method. GitHub IssuesEvents carry a JSON payload that gives details of the issue that triggered the event.
The 'action' field shows what caused the event. The ones we're interested in are label modifications and edits.
When an issue is edited, we update the corresponding record.
When an issue is labeled, we add the issue to the corresponding list.
Likewise, we remove issues from lists when they are unlabeled.
Feel free to look through the rest of the code on GitHub. If you want a challenge, perhaps try to allow moving cards on the frontend and modify the corresponding issues on GitHub!
deepstreamHub is funded with resources from the Pro FIT program. The Pro FIT project is co-financed with funds from the European Fund for Regional Development (EFRE) with the goal to research, develop and market enterprise-ready deepstreamHub features.
Как подключить github api java
This library defines an object oriented representation of the GitHub API. By «object oriented» we mean there are classes that correspond to the domain model of GitHub (such as GHUser and GHRepository ), operations that act on them as defined as methods (such as GHUser.follow() ), and those object references are used in favor of using string handle (such as GHUser.isMemberOf(GHOrganization) instead of GHUser.isMemberOf(String) )
The library supports both github.com and GitHub Enterprise.
Most of the GitHub APIs are covered, although there are some corners that are still not yet implemented.
Sample Usage
Authentication
The library allows connecting to GitHub via several different authentication mechanisms.
Programmatically
To connect via Username and Password (not recommended):
To connect via Personal access token:
To connect via JWT token as a GitHub App:
To connect via GitHub App installation token on behalf of a user or organization:
Property file
This library defines a common convention so that applications using this library will look at a consistent location. In this convention, the library looks at
/.github property file. The content of the files depends on the way you want this library to authenticate as shown below:
To connect via Username and Password (not recommended):
To connect via Personal access token:
To connect via Personal access token as a user or organization:
To connect via JWT token as a GitHub App:
/.github property file is properly configured, you can obtain a GitHub instance using:
Environmental variables
This library also allows developers to authenticate GitHub with environmental variables.
To connect via Username and Password (not recommended):
To connect via Personal access token:
To connect via Personal access token as a user or organization:
To connect via JWT token as a GitHub App:
Once exported, you can obtain a GitHub instance using:
Pluggable HTTP client
This library comes with a pluggable connector to use different HTTP client implementations through HttpConnector . In particular, this means you can use OkHttp, so we can make use of it’s HTTP response cache. Making a conditional request against the GitHub API and receiving a 304 response does not count against the rate limit.
The following code shows an example of how to set up persistent cache on the disk:
How to Improve Your Java Workflow with GitHub API
By now, you have probably heard about the GitHub API. Or you know what GitHub is and you know what an API is. Or you just Googled it, that’s okay too.
From automating GitHub processes to just being a command line fanatic, the GitHub API can be used in many different ways. By taking a brief look at the documentation, you can see the GitHub API can do just about everything and more.
Stay tuned to find out many cool features you probably didn’t know the GitHub API has and make your automation process a walk in the park.
Read to the end for a quick and easy tutorial!
The Convenience of GitHub API
As many enterprises use GitHub in their everyday work, it may not come as a surprise to learn the base URL can be different from those which are public repositories.
The most difficult part in the entire process is actually this — find out what the base URL of your enterprise is. Seems easy, right? The base URL of your enterprise can look something like https://<your.enterprise>.githubname.com/api/v3 .
The v3 in this case stands for version 3, the current version of the GitHub API,while the public GitHub base URL is https://api.github.com .
Once you have found the base URL, keep it somewhere safe — perhaps the part of your brain where it will never be forgotten, you’ll most likely need to create a Personal Access Token (PAT). This can be done by following the official GitHub docs tutorial. If you already have a token, you can just use that one.
You’ll need this token for any kind of request that requires authorization, especially if you want to do more complex tasks than just calling a few GET requests against a public GitHub repository. For these requests, you’ll need to add a Header to the request as such:
Now you’re ready to dive into the fun world of making requests.
SHA-1 values
To make everything easier to find and understand, commits in git have their own Secure Hash Algorithm 1 (SHA-1) value. Other objects in GitHub have sha tokens that point back to the commit, so we can identify the objects using these values.
The easiest way to obtain an SHA-1 value for an object is to store the response when creating said object.
The other way is to fish out the value through a GET request against the object. This way is slightly more difficult, as you would need to know specific information such as an exact pull request number, commit number, or branch name.
Creating and deleting references
Any self-respecting software engineer will tell you to never simply push your code to the master branch. Instead you need to manually create a new branch every time run the code you’d like to automate. That seems quite upsetting.
Just as you’re wondering if there’s even hope to ever sit back and sip your coffee while your code just does its thing, the GitHub API comes to the rescue.
You can create branches with one request:
That has required 2 body parameters:
- ref (string) — the name of the branch you’d like to create (i.e refs/heads/[your_branch_name])
- sha (string) — sha token value of the branch you’d like to create a branch on
After hitting send, your new branch will appear like clockwork.
Getting tired of your new snazzy branch? Has it served its purpose? Perhaps you named it incorrectly? Fear not, you can also delete the reference without leaving a trace through the GitHub API. All you’ll need is the name of the branch you just created.
Poof, gone. Nobody will ever need to know.
Creating and updating content
Say you’re using a dependency in a project and you always want to have the latest version on hand. Why waste your valuable time on doing things manually, when you can just click one button and have a computer update the dependencies for you? I mean, that’s where we’re headed with automation, right?
Yet again, the GitHub API can create or update content with a simple request.
The request will create a commit. This time, you’ll have 2 required body parameters (3 if you’re looking to update an existing file):
- message (string) — the commit message
- content (string) — the content of the entire file in Base64 encoding. You can use the built-in Java Base64 functionality.
- sha (string) — the blob SHA of the file being replaced (necessary only if updating a file)
There are a few optional parameters, but if you feel like using your flashy new branch, you can add an extra parameter:
- branch (string) — the name of your branch
A commit will have been created and your file successfully created/updated. You can thank the GitHub API later.
Manage pull requests (PRs)
As you may have guessed by now, the GitHub API can handle PRs without you having to leave the comfort of your command line or your favourite IDE.
The GitHub API can open PRs, merge them, add reviews to them and so on, but out of the many capabilities, a favorite task has to be- checking their statuses.
Depending on where you work, the PRs may have several checks that have to pass before they can be merged to the master branch. Imagine having a process automated, but not being able to merge your branch, because it’s just not ready yet.
Our superhero of the day can and will assist you. You can use this request to check the status of your PR.
In this case, the ref would be the SHA of one of the commits in your PR.
The status of a PR can either be pending, success or failure. Adding a simple while loop and checking in every now and then will allow your code to keep running after a small wait for your PR to be in the success status.
Let’s Get Started
After all of that reading, it’s time for you to warm up your fingers with a quick exercise. We’ll create a Java project that calls the GitHub API to create a branch, create a file, create a pull request, merge the pull request and delete the branch.
Setup
If at any point you are having any trouble, you can refer to the working code on my personal GitHub.
In this example, I will be creating my project as a Maven project, so I could use third party libraries without having to find them, download them and add them to my classpath.
Using JetBrains IntelliJ, select New Project.
From the dropdown menu on the left, select Maven.
Choose your cloned repository and name the project as you wish. For the purpose of this article, I’m naming the project as “github-api-test”, as seen in the screenshot below:
Your project structure should look like this. You can take a look at the pom.xml file and get acquainted. Also set the maven compiler version here as we will be using Java 11 features:
Start by creating a new Java class like so:
Before diving into everything, we can make our lives easier by preparing 4 different requests: GET, PUT, POST and DELETE — these requests will return us the response body. To get a better understanding of this, you can check out 5 ways to make HTTP requests in Java. We will be reusing these methods to avoid writing duplicate code. To keep things simple and maintainable, we’ll have a few constants — the base URL of your GitHub and your PAT. We will also be adding an object mapper, more about this in Three ways to use Jackson for JSON in Java. Add these to the very beginning of your class.
GitHub Integration using Java GitHub
tutorials → integrations → GitHub Integration using Java
- Activity Streams
- Android Chat App
- Coffee Order System
- Collaborative Post-It Board
- IoT Light Sensor
- Music Collection
- Pizza Delivery Tracker
- Realtime Cart
- Realtime Chat in Browser
- Comment Feed using Vue
- Realtime Flight Tracker
- Realtime Todo List
- Android
- Angular 2
- AngularJS
- C++
- HTTP
- Ionic 2
- Java
- JavaScript
- Node
- Preact
- React
- React Native
- Swift
- VueJS
- Authentication
- Email Auth
- HTTP Webhook Auth
- Open Auth
- Features
- Events
- Remote Procedure Calls
- General
- Handling Data Conflicts
- Security Overview
- Permissioning
- User-specific data
- Valve advanced
- Valve Realtime
- Valve simple
- Realtime Database
- Anonymous Records
- Lists
- Records
- AWS Lambda
- AWS SNS
- GitHub
- Mailchimp
- Nexmo
- Pusher
- Sendgrid
- Slack
- Twilio
- WebRTC
- WebRTC 03: Audio & Video
- WebRTC 01: Data Channels
- WebRTC 06: File Transfer
- WebRTC 02: Full Mesh
- WebRTC: in production
- WebRTC: Fundamentals & Concepts
- WebRTC 06: Screen Sharing
- WebRTC 05: Video Manipulation
- Realtime Database
- Modelling relational data
- Realtime Events
- Live Progress Bar
In this post, we’ll be building a simple GitHub issue tracker similar to waffle.io. It will show active issues on a project with specific workflow labels, and it will update in real time as issues are created and updated on GitHub.
This post will focus on building a connector using deepstream’s Java API and Kohsuke Kawaguchi’s GitHub API for Java. I will assume a basic understanding of Java. If you haven’t already, take a look at Getting Started with Java. For brevity, we won’t cover how to build the React.js frontend, but feel free to take a look at the one provided. If you’d like to read more about integrating deepstream with React.js, read getting started with React.
Setting Up
If you’d like to follow along, you can clone the completed project on GitHub.
Create a free account and get your API key
Create an application through the deepstreamHub dashboard, and make a note of the corresponding application url.
Within the client directory, run npm install to install the client dependencies, then run python -m SimpleHTTPServer to start a test server. You should then be able to view the client at localhost:8000.
Create a GitHub personal access token with repository access. Then create a file
It’s also possible to put your GitHub credentials in this file to avoid this step — see here.
I recommend setting up a test GitHub repository with some issues, and labeling some of them with ‘roadmap’, ‘ready’, ‘in progress’, ‘awaiting review’, or ‘in review’. It’s also a good idea to give those labels some nice colors — we’ll be using those later on.
Install ngrok which will allow us to listen for external connections from the webhook we’ll use later on. Start it using ngrok http 8080 , and make note of the forwarding address.
We’re using Gradle to manage dependencies.
Project Setup
In our main method, we set the details of our local deepstream server, the webhook URI given when you start ngrok, and the GitHub repository that we’re getting our issues from.
You’ll need to update the WEBHOOK_URI , DEEPSTREAM_URI and GITHUB_REPO environment variables in your build system to get the connector to run locally.
Setting up API Objects
We first setup a connection to our deepstream client.
. then setup a connection to GitHub.
Initial State
Our connector will need to fetch any open issues from GitHub’s API and create corresponding records in deepstream for rendering in the client.
Interesting Labels
We only care about certain labels, so we’ll create a list of these and add them to a deepstream list.
Issue Lists
Now we can start inserting issues into lists based on which labels they have.
In our initializeIssueLists() method, we make deepstream lists for each of the labels and ensure that they’re empty.
We get a list of open issues from GitHub.
Then we add each issue to all the lists for each label it has.
However, we’re only interested in some of the labels. We also want to create a record with our issue id to store the issue data.
We call this method from the constructor.
Coloring Labels
GitHub allows each label to have a color, so we get that from the API and pass it to the client for rendering.
Inside our setupIssueColors method, we simply create a deepstream record that maps label names to hex colors.
Realtime Updates
We use the GitHub webhook API to receive updates when issues are modified.
Event Listener
First, we start a server to listen for webhook events.
Our startServer() method instantiates the RequestHandler, which we’ll describe shortly.
Subscribe to Issue Events
So that we are notified when the issues are modified, we subscribe through the GitHub webhook API, specifying GHEvent.ISSUES , as this is the only event we’re interested in.
Handling Events
Events are handled in the RequestHandler.handle() method. GitHub IssuesEvents carry a JSON payload that gives details of the issue that triggered the event.
The ‘action’ field shows what caused the event. The ones we’re interested in are label modifications and edits.
When an issue is edited, we update the corresponding record.
When an issue is labeled, we add the issue to the corresponding list.
Likewise, we remove issues from lists when they are unlabeled.
Feel free to look through the rest of the code on GitHub. If you want a challenge, perhaps try to allow moving cards on the frontend and modify the corresponding issues on GitHub!
deepstreamHub is funded with resources from the Pro FIT program. The Pro FIT project is co-financed with funds from the European Fund for Regional Development (EFRE) with the goal to research, develop and market enterprise-ready deepstreamHub features.
Учебник. Как реализовать Java OAuth 2.0 для входа в GitHub и Google
Одна из последних функций, которую мы добавили в Takipi, – это сторонняя регистрация. Если вы ленивы, как и я, то вы, вероятно, предпочитаете пропустить заполнение форм и создание новых паролей . Когда доступно, многие люди предпочитают сторонний вход, если запрашиваемые разрешения не являются навязчивыми – никто не хочет, чтобы случайные записи отображались на их стене Facebook, поэтому такой доступ включает только пользователя Основная информация, как имя и адреса электронной почты. В этом посте вы получите краткий обзор того, как мы реализовали это в Takipi, как вы можете использовать стороннюю регистрацию в своем приложении, а также несколько полезных советов, которые помогут вам сэкономить драгоценное время, если вы решите интегрировать это с вашим собственным приложением.
Новая статья: Как реализовать Java OAuth 2.0 для входа в систему с помощью GitHub и Google http://t.co/20Hn59dCtf pic.twitter.com/3tNNwPKjET
– Такипи (@takipid) 14 мая 2015 г.
Оказалось, что в нашей маленькой вселенной я не одинок в этом, и многие из наших пользователей чувствуют то же самое. Поскольку мы являемся стартапом инструментов разработчика, использование входа в GitHub и Google от сторонних разработчиков имело смысл. Помимо удобства для ваших пользователей, использование сторонних сервисов может повысить их безопасность. Поскольку Google и GitHub используют двухфакторную аутентификацию (2FA), ваше приложение получает этот уровень безопасности «бесплатно». В нашем случае мы уже включили 2FA, поэтому я думаю, что это делает нас… 3FA & # 55357; & # 56859;
Предварительный просмотр макета для нашей новой домашней страницы с помощью сторонних кнопок входа
Чтобы увидеть, как это работает на практике, вы можете проверить эту страницу, которую мы использовали для внутреннего тестирования. Это полностью работает, но обновление пока не доступно на сайте. Здесь у вас есть редкая возможность одним из первых использовать его
Напомни мне, как снова работает OAuth 2.0?
Процесс входа в OAuth выглядит следующим образом: пользователь заходит на ваш сайт, нажимает кнопку «Войти с помощью чего угодно» и перенаправляется на страницу разрешений. Страница разрешений поступает от Whither ™, и когда они одобряют запрашиваемые вами разрешения, Whither ™ отправляет им токен, который его браузер затем отправляет на серверную часть вашего приложения. Как только у вас есть токен, вы отправляете его обратно в Wh Wh ™ для проверки и, если он проверен – вы получаете доступ к данным, для которых вам были предоставлены разрешения.
Библиотека Google OAuth2.0
Для реализации стороннего входа на нашем сайте мы использовали клиентскую библиотеку API Google для Java. В нем также есть Jackson2, ProtoBuf и все другие полезные утилиты, которые появляются в топ-100 библиотек, которые используются в лучших Java-проектах GitHub . Это был довольно простой выбор для нас, так как мы уже использовали эту библиотеку для других целей, и, честно говоря, библиотека Google появилась как первый результат на … Google. Подготовьте свои шляпы из фольги .
Реализация входа с помощью Google
Это была легкая часть путешествия; документация на конце Google была ясна и по существу. Так как это их собственная библиотека, они также абстрагируют части процедуры и обрабатывают ее за кулисами, что делает ее еще более простой в реализации. Первым шагом будет создание проекта на консоли разработчика Google, где вы сможете зарегистрировать свое приложение и настроить страницу разрешений.
Страница разрешений Google – настроенная для Takipi
Теперь вернемся к Java. В основе этого, процедура сводится к нескольким простым шагам без сюрпризов. Сначала мы создаем и выполняем запрос для получения GoogleTokenResponse, чтобы мы могли проверить токен, полученный от пользователя. Затем мы используем этот ответ для создания GoogleCredential, который позволяет нам вызывать getAccessToken () и возвращать информацию о пользователе в формате JSON:
How do I build a Github API for Java, in Eclipse?
I am trying to build Github API for Java in Eclipse. I download the project from the link https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core and follow the readme’s instructions about the build using a pom/xml file. Then I execute the maven’s command as it is described but errors occured.
Maven commands in readme file are :
The GitHub Java API is built using Apache Maven.
Run the following command to build a JAR file containing the GitHub Java API without dependencies:
The GitHub Java API can also be built as a JAR that includes all the dependencies (Google Gson). This technique uses the Maven Shade Plugin to build an all-in-one JAR file.
This happens when i execute the maven command $ mvn package or the command described in read me file.
I am using Maven for first time so I cant find where the problem is. Maybe I have to move egit-github-master folder in other specific directory or I am using the wrong commands to build?