Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TC-1223 -- jira plugin #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src-plugins/jira/jira.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"os"
"io/ioutil"
"encoding/json"
jira "gopkg.in/andygrunwald/go-jira.v1"
"fmt"
)

type API struct {
Username string `json:"username"`
Password string `json:"password"`
Server string `json:"server"`
Project string `json:"project"`
Assignee string `json:"assignee"`
}

type AlertText struct {
Html string `json:"html"`
PlainText string `json:"plain"`
}

type AlertAPI struct {
Text AlertText `json:"text"`
Settings API `json:"settings"`
}

func readAPI(path string) AlertAPI {
var api AlertAPI
tmp, err := ioutil.ReadFile(os.Args[1])
if err != nil { fmt.Println("Cannot read API file: ", path) ; os.Exit(1) } //cannot read input JSON
err = json.Unmarshal(tmp, &api)
if err != nil { fmt.Println("Cannot read API JSON: ", path) ; os.Exit(1) } //cannot read input JSON
return api
}

func main() {
// Parse the input API
api := readAPI(os.Args[1])
tp := jira.BasicAuthTransport{
Username: api.Settings.Username,
Password: api.Settings.Password,
}

jiraClient, err := jira.NewClient(tp.Client(), api.Settings.Server)
if err != nil {
panic(err)
}

i := jira.Issue{
Fields: &jira.IssueFields{
Assignee: &jira.User{
Name: api.Settings.Assignee,
},
Reporter: &jira.User{
Name: api.Settings.Username,
},
Description: "Test Issue",
Type: jira.IssueType{
Name: "Bug",
},
Project: jira.Project{
Key: api.Settings.Project,
},
Summary: api.Text.PlainText,
},
}
issue, response, err := jiraClient.Issue.Create(&i)
if err != nil {
fmt.Printf(err.Error())
body, _ := ioutil.ReadAll(response.Body)
fmt.Println(string(body))
panic(err)
}

fmt.Printf("%s: %+v\n", issue.Key, issue.Fields.Summary)
}
47 changes: 47 additions & 0 deletions src-plugins/jira/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "jira",
"summary": "Jira service integration",
"description": "Forward alerts to Jira as new tickets.",
"icon_url": "",
"version": "1.0",
"date_released": "2020-02-08",
"tags": ["jira", "ticketing", "service", "issue", "tracker"],
"maintainer": [
{ "name": "Aaron Ervin", "email": "[email protected]" },
{ "name": "iXsystems", "email": "[email protected]", "site_url": "http://ixsystems.com" }
],
"exec": "jira",
"depends": [],
"api": [
{
"fieldname": "username",
"summary": "Jira user",
"value": { "type": "string" },
"is_required": true
},
{
"fieldname": "password",
"summary": "User password",
"value": { "type": "string" },
"is_required": true
},
{
"fieldname": "server",
"summary": "Jira server address",
"value": { "type": "string" },
"is_required": true
},
{
"fieldname": "project",
"summary": "Jira project prefix",
"value": { "type": "string" },
"is_required": true
},
{
"fieldname": "assignee",
"summary": "Username of issue assignee",
"value": { "type": "string" },
"is_required": true
}
]
}