Skip to content

Commit

Permalink
Merge pull request #1 from kdobmayer/master
Browse files Browse the repository at this point in the history
Parse env vars into the step config
  • Loading branch information
amrfarid140 authored Mar 16, 2018
2 parents f8a9b23 + 9d35143 commit ac3283b
Showing 18 changed files with 810 additions and 104 deletions.
26 changes: 26 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[constraint]]
name = "github.com/bitrise-tools/go-steputils"
branch = "master"

[prune]
go-tests = true
unused-packages = true
25 changes: 1 addition & 24 deletions bitrise.yml
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ app:
envs:
# An example secret param, define it (A_SECRET_PARAM) in .bitrise.secrets.yml
- STEP_VERSION: 1.0.1
- INCOMING_WEBHOOK_URL : $INCOMING_WEBHOOK_URL
# If you want to share this step into a StepLib
- BITRISE_STEP_ID: microsoft-teams-integration
- BITRISE_STEP_VERSION: "1.0.1"
@@ -15,33 +14,11 @@ app:
workflows:
test:
steps:
- script:
inputs:
- content: |
#!/bin/bash
echo "Just an example 'secrets' print."
echo "The value of 'A_SECRET_PARAM' is: $A_SECRET_PARAM"
- change-workdir:
title: Switch working dir to test / _tmp dir
description: |-
To prevent step testing issues, like referencing relative
files with just './some-file' in the step's code, which would
work for testing the step from this directory directly
but would break if the step is included in another `bitrise.yml`.
run_if: true
inputs:
- path: ./_tmp
- is_create_path: true
- path::./:
title: Step Test
run_if: true
inputs:
- INCOMING_WEBHOOK_URL,required: https://outlook.office.com/webhook/5bdfe871-8b29-47d0-82dc-4fd42e02d0b9@dacd0a8f-30ed-4ee0-ad06-de7c7aa659ed/IncomingWebhook/6bcb8d7d07e04dc5880a0830c1e861a0/a05f31c9-bb92-46a8-bbdb-371c36e8902c
- script:
inputs:
- content: |
#!/bin/bash
echo "This output was generated by the Step (EXAMPLE_STEP_OUTPUT): $EXAMPLE_STEP_OUTPUT"
- webhook_url: https://outlook.office.com/webhook/5bdfe871-8b29-47d0-82dc-4fd42e02d0b9@dacd0a8f-30ed-4ee0-ad06-de7c7aa659ed/IncomingWebhook/6bcb8d7d07e04dc5880a0830c1e861a0/a05f31c9-bb92-46a8-bbdb-371c36e8902c


# ----------------------------------------------------------------
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main

// Config will be populated with the retrieved values from environment variables
// config will be populated with the retrieved values from environment variables
// configured as step inputs.
type Config struct {

// Message
type config struct {
BuildNumber string `env:"BITRISE_BUILD_NUMBER"`
AppTitle string `env:"BITRISE_APP_TITLE"`
AppURL string `env:"BITRISE_APP_URL"`
BuildURL string `env:"BITRISE_BUILD_URL"`
RepoURL string `env:"GIT_REPOSITORY_URL"`
GitBranch string `env:"BITRISE_GIT_BRANCH"`
AppImageURL string `env:"BITRISE_APP_SLUG"`

WebhookURL string `env:"webhook_url,required"`
}
41 changes: 22 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
@@ -7,23 +7,25 @@ import (
"io/ioutil"
"net/http"
"os"

"github.com/bitrise-tools/go-steputils/stepconf"
)

func newMessage(buildOk bool, conf Config) Message {
func newMessage(buildOk bool, cfg config) Message {
message := Message{}
message.Type = "MessageCard"
message.Context = "http://schema.org/extensions"
message.ThemeColor = "0076D7"
if buildOk {
message.Summary = fmt.Sprintf("%s build number %s succeeded", conf.AppTitle, conf.BuildNumber)
message.Summary = fmt.Sprintf("%s build number %s succeeded", cfg.AppTitle, cfg.BuildNumber)
} else {
message.Summary = fmt.Sprintf("%s build number %s failed", conf.AppTitle, conf.BuildNumber)
message.Summary = fmt.Sprintf("%s build number %s failed", cfg.AppTitle, cfg.BuildNumber)
}
message.Markdown = "true"
section := Section{}
section.AppTitle = fmt.Sprintf("![AppImage](%s)%s", conf.AppImageURL, conf.AppTitle)
section.BuildNumber = conf.BuildNumber
section.AppImage = conf.AppImageURL
section.AppTitle = fmt.Sprintf("![AppImage](%s)%s", cfg.AppImageURL, cfg.AppTitle)
section.BuildNumber = cfg.BuildNumber
section.AppImage = cfg.AppImageURL

buildStatusFact := Fact{}
buildStatusFact.Name = "Build Status"
@@ -35,11 +37,11 @@ func newMessage(buildOk bool, conf Config) Message {

buildNumberFact := Fact{}
buildNumberFact.Name = "Build Number"
buildNumberFact.Value = conf.BuildNumber
buildNumberFact.Value = cfg.BuildNumber

buildBranchFact := Fact{}
buildBranchFact.Name = "Git Branch"
buildBranchFact.Value = conf.GitBranch
buildBranchFact.Value = cfg.GitBranch

section.Facts = []Fact{buildStatusFact, buildNumberFact, buildBranchFact}

@@ -51,15 +53,15 @@ func newMessage(buildOk bool, conf Config) Message {
goToRepoActionCardAction := Action{}
goToRepoActionCardAction.Type = "HttpGet"
goToRepoActionCardAction.Name = "Go To Repo"
goToRepoActionCardAction.Target = conf.RepoURL
goToRepoActionCardAction.Target = cfg.RepoURL

goToBuildActionCard := ActionCard{}
goToBuildActionCard.Type = "ActionCard"
goToBuildActionCard.Name = "Go To Build"
goToBuildActionCardAction := Action{}
goToBuildActionCardAction.Type = "HttpGet"
goToBuildActionCardAction.Name = "Go To Build"
goToBuildActionCardAction.Target = conf.BuildURL
goToBuildActionCardAction.Target = cfg.BuildURL

message.Actions = []ActionCard{goToRepoActionCard, goToBuildActionCard}

@@ -96,19 +98,20 @@ func postMessage(webhookURL string, msg Message) error {
}

func main() {
var webhookURL = os.Getenv("INCOMING_WEBHOOK_URL,required")
// success is true if the build is successful, false otherwise.
fmt.Println(fmt.Sprintf("Webhook URL: %s", os.Getenv("INCOMING_WEBHOOK_URL,required")))
var cfg config
if err := stepconf.Parse(&cfg); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
stepconf.Print(cfg)

var success = os.Getenv("BITRISE_BUILD_STATUS") == "0"
var conf Config
message := newMessage(success, conf)
if err := postMessage(webhookURL, message); err != nil {
// success is true if the build is successful, false otherwise.
success := os.Getenv("BITRISE_BUILD_STATUS") == "0"
message := newMessage(success, cfg)
if err := postMessage(cfg.WebhookURL, message); err != nil {
fmt.Println(fmt.Sprintf("Error: %s", err))
os.Exit(1)
}

fmt.Println("Message successfully sent!")

os.Exit(0)
}
37 changes: 13 additions & 24 deletions message.go
Original file line number Diff line number Diff line change
@@ -1,57 +1,46 @@
package main

// Message to post to a slack channel.
// See also: https://api.slack.com/methods/chat.postMessage
// Message to send to Microsoft Teams.
type Message struct {
// Channel to send message to.
//
// Can be an encoded ID (eg. C024BE91L), or the channel's name (eg. #general).
Type string `json:"@type"`

// Text of the message to send. Required, unless providing only attachments instead.
Context string `json:"@context"`

ThemeColor string `json:"themeColor"`

Summary string `json:"summary"`

Markdown string `json:"markdown"`

Sections []Section `json:"sections"`

Actions []ActionCard `json:"potentialAction"`
Type string `json:"@type"`
Context string `json:"@context"`
ThemeColor string `json:"themeColor"`
Summary string `json:"summary"`
Markdown string `json:"markdown"`
Sections []Section `json:"sections"`
Actions []ActionCard `json:"potentialAction"`
}

//Section to be shown in the message
// Section to be shown in the message
type Section struct {
AppTitle string `json:"activityTitle"`
BuildNumber string `json:"activitySubtitle"`
AppImage string `json:"activityImage"`
Facts []Fact `json:"facts"`
}

//Fact realted to the message
// Fact realted to the message
type Fact struct {
Name string `json:"name"`
Value string `json:"value"`
}

//ActionCard to be added to the message
// ActionCard to be added to the message
type ActionCard struct {
Type string `json:"@type"`
Name string `json:"name"`
Inputs []ActionInput `json:"inputs"`
Actions []Action `json:"actions"`
}

//ActionInput for actions if any
// ActionInput for actions if any
type ActionInput struct {
Type string `json:"@type"`
ID string `json:"id"`
Title string `json:"title"`
}

//Action to be taken by the action card
// Action to be taken by the action card
type Action struct {
Type string `json:"@type"`
Name string `json:"name"`
42 changes: 9 additions & 33 deletions step.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#
# A couple of useful guides & docs:
#
# - Main Bitrise CLI docs: https://github.com/bitrise-io/bitrise/tree/master/_docs
# - Step Development Guideline: https://github.com/bitrise-io/bitrise/blob/master/_docs/step-development-guideline.md
# - Bitrise.yml format spec: https://github.com/bitrise-io/bitrise/blob/master/_docs/bitrise-yml-format-spec.md
# - Bitrise docs: http://devcenter.bitrise.io/
# - Bitrise CLI guides: http://devcenter.bitrise.io/bitrise-cli/
title: |-
Microsoft Teams Integration
summary: |
Allows you to recieve build status updates on Microsoft Team using Incoming Webhooks
---
title: Microsoft Teams Integration
summary: Allows you to recieve build status updates on Microsoft Team using Incoming Webhooks
description: |
Uses Incoming Webhooks feature in Microsft Teams to send updates on your builds
website: https://github.com/amrfarid140/bitrise-step-microsoft-teams-integration
@@ -18,43 +9,28 @@ support_url: https://github.com/amrfarid140/bitrise-step-microsoft-teams-integra
host_os_tags:
- osx-10.10
- ubuntu-16.04


# Type tags are used for categorizing steps, for easier step discovery in Step Libraries.
# You can find more information about type tags in the Step Development Guideline:
# https://github.com/bitrise-io/bitrise/blob/master/_docs/step-development-guideline.md
type_tags:
- notification

is_requires_admin_user: true
is_always_run: false
is_always_run: true
is_skippable: true
run_if: ""

deps:
brew:
- name: git
- name: wget
- name: go
apt_get:
- name: git
- name: wget


- name: golang
bin_name: go
toolkit:
go:
package_name: github.com/amrfarid140/bitrise-step-microsoft-teams-integration


inputs:
- INCOMING_WEBHOOK_URL,required:
- webhook_url:
opts:
title: "Incoming Webhook URL"
summary: Url of the "Incoming Webhook URL" generated by Microsoft Teams
summary: "Url of the Incoming Webhook generated by Microsoft Teams"
description: |
* Go to Microsoft Teams
* Click on the three dots next to channel name then **Add Connector**
* Select **Incoming Webhook* and in the text input type **Bitrise**
* Save and copy the link to the input for this step
is_expand: true
is_required: true
value_options: []
22 changes: 22 additions & 0 deletions vendor/github.com/bitrise-io/go-utils/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ac3283b

Please sign in to comment.