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

(DRON-166) adding adaptive card. minor fixes #3

Merged
merged 1 commit into from
Feb 7, 2022
Merged
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
20 changes: 19 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@

kind: pipeline
type: docker
name: default
name: testing

steps:
- name: build
image: golang
commands:
- go test ./...

---
kind: pipeline
type: docker
name: release

steps:
- name: build
image: golang
commands:
- sh scripts/build.sh

- name: publish
Expand Down Expand Up @@ -58,3 +68,11 @@ steps:
from_secret: docker_password
username:
from_secret: docker_username

depends_on:
- testing

trigger:
ref:
- refs/heads/master
- refs/tags/*
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
release/
drone-jira
NOTES*
output.json
.vscode/
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
A plugin to attach build and deployment details to a Jira issue.
# drone-jira

# Building
A plugin to attach build and deployment details to a Jira issue. For information on how to use the plugin with drone there is a video [here](https://youtu.be/YIKbLeY1-gI)

## Building

Build the plugin binary:

Expand All @@ -14,7 +16,7 @@ Build the plugin image:
docker build -t plugins/jira -f docker/Dockerfile .
```

# Testing
## Testing

Execute the plugin from your current working directory:

Expand All @@ -38,4 +40,4 @@ docker run --rm \
-w /drone/src \
-v $(pwd):/drone/src \
plugins/jira
```
```
9 changes: 9 additions & 0 deletions docs/card.data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pipeline": "drone",
"instance": "droneio",
"project": "TT",
"state": "unknown",
"version": "8f51ad7884c5eb69c11d260a31da7a745e6b78e2",
"environment": "production",
"url": "https://droneio.atlassian.net/browse/TT-1"
}
164 changes: 164 additions & 0 deletions docs/card.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"type": "AdaptiveCard",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"url": "https://drone.github.io/drone-jira/jira.png",
"size": "small"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "Plugin: Jira",
"wrap": true,
"size": "small",
"weight": "bolder",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "Project: ${project}",
"wrap": true,
"size": "Small",
"weight": "Lighter",
"isSubtle": true,
"spacing": "Small"
}
],
"width": "stretch"
}
],
"style": "default"
},
{
"type": "ColumnSet",
"style": "default",
"separator": true,
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "Pipeline:",
"wrap": true,
"size": "small",
"weight": "bolder",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "Environment:",
"wrap": true,
"size": "small",
"weight": "bolder",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "Instance:",
"wrap": true,
"size": "small",
"weight": "bolder",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "State:",
"wrap": true,
"size": "small",
"weight": "bolder",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "Version:",
"wrap": true,
"size": "small",
"weight": "bolder",
"isSubtle": false,
"spacing": "small"
}
],
"width": "auto"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "${pipeline}",
"wrap": true,
"size": "small",
"weight": "default",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "${environment}",
"wrap": true,
"size": "small",
"weight": "default",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "${instance}",
"wrap": true,
"size": "small",
"weight": "default",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "${state}",
"wrap": true,
"size": "small",
"weight": "default",
"isSubtle": false,
"spacing": "small"
},
{
"type": "TextBlock",
"text": "${version}",
"wrap": true,
"size": "small",
"weight": "default",
"isSubtle": false,
"spacing": "small"
}
],
"width": "auto"
}
]
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Open in Jira",
"url": "${url}"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.4"
}
Empty file added docs/index.json
Empty file.
Binary file added docs/jira.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module github.com/drone/drone-jira

go 1.12
go 1.17

require (
github.com/joho/godotenv v1.3.0
github.com/drone/drone-go v1.7.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/sirupsen/logrus v1.4.2
)

require (
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
)
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e/go.mod h1:Xa6lInWHNQnuWoF0YPSsx+INFA9qk7/7pTjwb3PInkY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/drone/drone-go v1.7.1 h1:ZX+3Rs8YHUSUQ5mkuMLmm1zr1ttiiE2YGNxF3AnyDKw=
github.com/drone/drone-go v1.7.1/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
41 changes: 41 additions & 0 deletions plugin/card.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package plugin

import (
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"os"

"github.com/drone/drone-go/drone"
)

func (args Args) writeCard(data Card) error {
result, _ := json.Marshal(data)
card := drone.CardInput{
Schema: "https://drone.github.io/drone-jira/card.json",
Data: result,
}
writeCard(args.CardFilePath, &card)
return nil
}

func writeCard(path string, card interface{}) {
data, _ := json.Marshal(card)
switch {
case path == "/dev/stdout":
writeCardTo(os.Stdout, data)
case path == "/dev/stderr":
writeCardTo(os.Stderr, data)
case path != "":
ioutil.WriteFile(path, data, 0644)
}
}

func writeCardTo(out io.Writer, data []byte) {
encoded := base64.StdEncoding.EncodeToString(data)
io.WriteString(out, "\u001B]1338;")
io.WriteString(out, encoded)
io.WriteString(out, "\u001B]0m")
io.WriteString(out, "\n")
}
Loading