How to connect OTRS with GitHub
Robert Ullrich19. Sep 2017 | Best PracticesConsultingUse cases
The practical examples presented in our technical blog (blog.otrs.com) and now in the expert category in our FAQ blog section serve as a source of ideas and documentation to show what is theoretically possible with OTRS in concrete scenarios or sometimes even for more exotic configurations. All configurations presented here were developed under laboratory conditions as a proof of concept.
We can only guarantee testing and implementation of these concepts to be error-free and productive if implemented in a workshop with one of our OTRS consultants. Without this, the responsibility lies with the customer himself. Please note that configurations from older OTRS versions may not work in the newer ones.
Last time I had a requirement of a customer, who wanted to connect OTRS with the GitHub account of his company. I think this might also be an interesting use case for you. In this small blog article you can learn, how to create an issue in GitHub via OTRS, to receive the latest information on a GitHub issue and to create comments for an issue in GitHub.
To complete this Howto, you need a running OTRS & a valid GitHub repository. Furthermore, you need a valid user login and the “access_token” of the user which should be used for the integration. The REST/JSON API of GitHub can be used by everyone, who has a GitHub account.
Use case for this connector
The GitHubConnector can be used in software developing companies, where the customer service team is using OTRS for the requests of customers and the development department is using GitHub for maintaining the source code, work on open issues a.s.o. To improve the communication (and to prevent agents to work on two different systems) you can use the GitHubConnector of this article.
OTRS Requirements for this HowTo
- at least OTRS 5.0.x
You need the following Freely selectable Features of the OTRS Business Solution™ 5s :
(Adds new invoker for TicketCreate and TicketUpdate in the GenericInterface.)
(Contains additional functionalities to add conditions to events of invokers.)
Third Party Software
You need this third party software:
- “GitHubIssueID” of type „TEXT“ to store the GitHub issue id (e.g.: 1)
- “GitHubCreateTime” of type “TEXT” to store the timestamp, when the issue was created
- “GitHubUpdateTime” of type “TEXT” to store the last update time of the issue in GitHub
- “GitHubIssueState” of type “TEXT” to store the latest state of the issue from GitHub
Configuring the GitHubConnector in OTRS
After you satisfied the pre-requirements, you’re ready to create a new web service within OTRS. The name of the new web service is “GitHubConnector”. Afterwards, you have to set up the needed invokers.
Configuring the Invoker “IssueCreate”
Now you’re ready to start the configuration of our Invokers. To be able to create issues in Github, you have to set up an Invoker called “IssueCreate”. Select all the needed data for your outgoing requests and use “XSLT” as mapping for your outgoing and incoming response data.
For the incoming response data, you have to select the dynamic fields (GitHubIssueID, GitHubCreateTime, GitHubLastUpdate and GitHubIssueState), which you created before.
For our XSLT mapping we need at least the following elements:
|title||string||Required. The title of the issue.|
|body||string||The contents of the issue.|
Now you can configure your outgoing XSLT-mapping. If you need a working XSLT-mapping, you can use the following example:
You also need a XSLT-mapping for the incoming response data, because you have to store the GitHub Issue ID, the Create Time the Last Update Time and the GitHub Issue State:
OTRS stores the GitHub Issue ID in the dynamic field “GitHubIssueID”. Afterward, it’s shown in the OTRS TicketZoom.
Furthermore, we want to know the latest State of the GitHub Issue, that’s the reason why it’s also stored in a dynamic field
The used “Event trigger” is the last point for this invoker. Just select one and you’re done with the first Invoker.
Configuring the Invoker “IssueGet”
The next invoker is “IssueGet”. Select all the needed data for your outgoing requests (please don’t forget the dynamic field “GitHubIssueID” in the “Ticket dynamic fields” drop-down) and use “XSLT” as a mapping for your outgoing data.
As outgoing XSLT-mapping, you can use my example. I will transmit the Issue ID to GitHub because I want to get the latest Issue state.
A mapping for the incoming response data is necessary because we want to store the “LastUpdate” timestamp and the latest Issue state.
The used “Event Trigger” is the last point for this Invoker. Just select one and you’re done with the second Invoker. In my example, I’m using a dynamic field update, which is automatically set by a GenericAgent.
Configuring the Invoker “NoteCreate”
The next invoker is “NoteCreate”. Select all the needed data for your outgoing requests (please don’t forget the dynamic field “GitHubIssueID” in the “Ticket dynamic fields” drop-down) and use “XSLT” as a mapping for your outgoing data.
Use my example as outgoing XSLT-mapping:
You don’t need a mapping for the incoming response data.
The used “Event trigger” is the last point. Select one and you’re done with the last Invoker of my tutorial. In my example I’m using an ArticleCreate event in OTRS, to trigger the Invoker.
Configuring the GitHubConnector “Network Transport”
It’s necessary to configure the network transport for the Invokers because we’ve to use the right requests commands towards GitHub.Otherwise we’ll receive errors. It’s quite easy as you can see:
We don’t have to use an authentication module because we’re using the access token of a specific user in our mapping.
Afterward just click on “Save and finish”.
Testing the GitHubConnector
Testing the Requester
Create or take an already existing ticket and trigger the “IssueCreate” Invoker.
As result you should see something similar in the OTRS Debugger:
In GitHub a new issue was created:
If we now trigger the Invoker “IssueGet” we’ll see the following in the Debugger:
OTRS is now requesting everything from GitHub for a specific issue and is mapping the data into our dynamic fields:
You’ll now see the following information in the TicketZoom:
And the last the Invoker is “NoteCreate”:
You can now see that the Note was created in GitHub:
More information about the GitHub API
You can also use other resources which are provided by the GitHub API.
If you need more information, please go to the following website: https://developer.github.com/v3/