-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
800 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Build and Test GitHub actions | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- dev | ||
- release/* | ||
|
||
jobs: | ||
build_and_test: | ||
name: Build and test the GitHub Action | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v1 | ||
|
||
- name: Run the private action | ||
uses: ./ | ||
with: | ||
webhook_uri: ${{ secrets.WEBHOOK_URI }} | ||
title: '' | ||
summary: 'GitHub Actions Message' | ||
text: '' | ||
theme_color: '' | ||
sections: '[{ "activityImage": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png", "activityTitle": "GitHub Action invoked", "activitySubtitle": "Event triggered by ${{ github.event.head_commit.author.name }}", "activityText": "Commit message: [${{ github.event.head_commit.message}}](${{ github.event.head_commit.url }})" }]' | ||
actions: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,3 +348,5 @@ MigrationBackup/ | |
|
||
# Ionide (cross platform F# VS Code tools) working folder | ||
.ionide/ | ||
|
||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build | ||
WORKDIR /app | ||
|
||
LABEL "com.github.actions.name"="Microsoft Teams (Generic)" | ||
LABEL "com.github.actions.description"="Send a message to the designated channel in Microsoft Teams" | ||
LABEL "com.github.actions.icon"="message-square" | ||
LABEL "com.github.actions.color"="purple" | ||
|
||
LABEL "repository"="http://github.com/aliencube/microsoft-teams-actions" | ||
LABEL "homepage"="http://github.com/aliencube" | ||
LABEL "maintainer"="Justin Yoo <no-reply@aliencube.com>" | ||
|
||
COPY *.sln . | ||
COPY src/ ./src/ | ||
|
||
ADD entrypoint.sh /entrypoint.sh | ||
RUN chmod +x /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D68A84FF-6FCD-43F0-8BE4-95E80B08C98A}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubActions.Teams.ConsoleApp", "src\GitHubActions.Teams.ConsoleApp\GitHubActions.Teams.ConsoleApp.csproj", "{AD57866E-EA88-459F-A0D9-536674AF120E}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{5C96E025-B004-4BF7-9FC7-3FD2D99BB1CD}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubActions.Teams.ConsoleApp.Tests", "test\GitHubActions.Teams.ConsoleApp.Tests\GitHubActions.Teams.ConsoleApp.Tests.csproj", "{CA78525C-AE74-4562-BC44-201722B8DF05}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Debug|x64.Build.0 = Debug|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Debug|x86.Build.0 = Debug|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Release|x64.ActiveCfg = Release|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Release|x64.Build.0 = Release|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Release|x86.ActiveCfg = Release|Any CPU | ||
{AD57866E-EA88-459F-A0D9-536674AF120E}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{AD57866E-EA88-459F-A0D9-536674AF120E} = {D68A84FF-6FCD-43F0-8BE4-95E80B08C98A} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,55 @@ | ||
# microsoft-teams-actions | ||
This is a GitHub Actions that sends a message to a given channel in Microsoft Teams | ||
# Microsoft Teams Actions # | ||
|
||
This is a GitHub Actions that sends a message to a given channel in Microsoft Teams, with the most generic way. | ||
|
||
|
||
## Inputs ## | ||
|
||
* `webhook-uri` (**Required**): Incoming webhook URI to Microsoft Teams | ||
* `title` (**Optional**): Message title | ||
* `summary` (**Required**): Message summary | ||
* `text` (**Optional**): Message text | ||
* `theme-color` (**Optional**): Message theme color | ||
* `sections` (**Optional**): JSON array for message sections | ||
* `actions` (**Optional**): JSON array for message actions | ||
|
||
## Outputs ## | ||
|
||
* `message`: Message sent to Microsoft Teams | ||
|
||
|
||
## Example Usage ## | ||
|
||
```yaml | ||
steps: | ||
name: Send a message to Microsoft Teams | ||
uses: aliencube/microsoft-teams-actions@v0.7.0 | ||
with: | ||
webhook-uri: <Microsoft Teams Incoming Webhook URI> | ||
title: <Message Title> | ||
summary: <Message Summary> | ||
text: <Message Text> | ||
theme-color: <Message Theme Color> | ||
sections: <JSON Array for Message Sections> | ||
actions: <JSON Array for Message Actions> | ||
``` | ||
## Contribution ## | ||
Your contributions are always welcome! All your work should be done in your forked repository. Once you finish your work with corresponding tests, please send us a pull request onto our `dev` branch for review. | ||
|
||
|
||
## License ## | ||
|
||
**Microsoft Teams Actions** is released under [MIT License](http://opensource.org/licenses/MIT) | ||
|
||
> The MIT License (MIT) | ||
> | ||
> Copyright (c) 2020 [aliencube.org](https://aliencube.org) | ||
> | ||
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Microsoft Teams (Generic) | ||
author: Aliencube Community | ||
description: Send a message to the designated channel in Microsoft Teams | ||
|
||
branding: | ||
icon: message-square | ||
color: purple | ||
|
||
inputs: | ||
webhook_uri: | ||
description: Incoming webhook URI to Microsoft Teams | ||
required: true | ||
title: | ||
description: Message title | ||
required: false | ||
default: '' | ||
summary: | ||
description: Message summary | ||
required: false | ||
default: '' | ||
text: | ||
description: Message text | ||
required: false | ||
default: '' | ||
theme_color: | ||
description: Message theme color | ||
required: false | ||
default: '' | ||
sections: | ||
description: JSON array for message sections | ||
required: false | ||
default: '' | ||
actions: | ||
description: JSON array for message actions | ||
required: false | ||
default: '' | ||
|
||
outputs: | ||
message: | ||
description: Message sent to Microsoft Teams | ||
|
||
runs: | ||
using: docker | ||
image: Dockerfile | ||
env: | ||
WEBHOOK_URI: ${{ inputs.webhook_uri }} | ||
TITLE: ${{ inputs.title }} | ||
SUMMARY: ${{ inputs.summary }} | ||
TEXT: ${{ inputs.text }} | ||
THEME_COLOR: ${{ inputs.theme_color }} | ||
SECTIONS: ${{ inputs.sections }} | ||
ACTIONS: ${{ inputs.actions }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh -l | ||
|
||
cd /app | ||
|
||
dotnet restore | ||
dotnet build | ||
dotnet run --project src/GitHubActions.Teams.ConsoleApp -- \ | ||
--webhook-uri "$WEBHOOK_URI" \ | ||
--title "$TITLE" \ | ||
--summary "$SUMMARY" \ | ||
--text "$TEXT" \ | ||
--theme-color "$THEME_COLOR" \ | ||
--sections "$SECTIONS" \ | ||
--actions "$ACTIONS" |
14 changes: 14 additions & 0 deletions
14
src/GitHubActions.Teams.ConsoleApp/GitHubActions.Teams.ConsoleApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommandLineParser" Version="2.7.82" /> | ||
<PackageReference Include="MessageCardModel" Version="1.0.5" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using CommandLine; | ||
|
||
namespace Aliencube.GitHubActions.Teams.ConsoleApp | ||
{ | ||
/// <summary> | ||
/// This represents the parameters entity for the console app. | ||
/// </summary> | ||
public class Options | ||
{ | ||
/// <summary> | ||
/// Gets or sets the incoming webhook URI to a Teams channel. | ||
/// </summary> | ||
[Option("webhook-uri", Required = true, HelpText = "Incoming webhook URI to Microsoft Teams")] | ||
public virtual string WebhookUri { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the message title. | ||
/// </summary> | ||
[Option("title", Required = false, Default = "", HelpText = "Message title")] | ||
public virtual string Title { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the message summary. | ||
/// </summary> | ||
[Option("summary", Required = true, HelpText = "Message summary")] | ||
public virtual string Summary { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the message text. | ||
/// </summary> | ||
[Option("text", Required = false, Default = "", HelpText = "Message text")] | ||
public virtual string Text { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the message theme colour. | ||
/// </summary> | ||
[Option("theme-color", Required = false, Default = "", HelpText = "Message theme color")] | ||
public virtual string ThemeColor { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the string representation of JSON array for the message sections. | ||
/// </summary> | ||
[Option("sections", Required = false, Default = "", HelpText = "JSON array for message sections")] | ||
public virtual string Sections { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the string representation of JSON array for the message actions. | ||
/// </summary> | ||
[Option("actions", Required = false, Default = "", HelpText = "JSON array for message actions")] | ||
public virtual string Actions { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Text; | ||
|
||
using CommandLine; | ||
|
||
using MessageCardModel; | ||
|
||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace Aliencube.GitHubActions.Teams.ConsoleApp | ||
{ | ||
/// <summary> | ||
/// This represents the console app entity. | ||
/// </summary> | ||
public static class Program | ||
{ | ||
private static JsonSerializerSettings settings { get; } = | ||
new JsonSerializerSettings() | ||
{ | ||
Formatting = Formatting.Indented, | ||
ContractResolver = new DefaultContractResolver() { NamingStrategy = new CamelCaseNamingStrategy() }, | ||
NullValueHandling = NullValueHandling.Ignore, | ||
MissingMemberHandling = MissingMemberHandling.Ignore, | ||
}; | ||
|
||
/// <summary> | ||
/// Invokes the console app. | ||
/// </summary> | ||
/// <param name="args">List of arguments passed.</param> | ||
public static void Main(string[] args) | ||
{ | ||
using (var parser = new Parser(with => { with.EnableDashDash = true; with.HelpWriter = Console.Out; })) | ||
{ | ||
parser.ParseArguments<Options>(args) | ||
.WithParsed<Options>(options => Process(options)); | ||
} | ||
} | ||
|
||
private static void Process(Options options) | ||
{ | ||
var card = new MessageCard() | ||
{ | ||
Title = ParseString(options.Title), | ||
Summary = ParseString(options.Summary), | ||
Text = ParseString(options.Text), | ||
ThemeColor = ParseString(options.ThemeColor), | ||
Sections = ParseCollection<Section>(options.Sections), | ||
Actions = ParseCollection<BaseAction>(options.Actions) | ||
}; | ||
|
||
var converted = JsonConvert.SerializeObject(card, settings); | ||
var message = (string)null; | ||
var requestUri = options.WebhookUri; | ||
|
||
using (var client = new HttpClient()) | ||
using (var content = new StringContent(converted, Encoding.UTF8, "application/json")) | ||
using (var response = client.PostAsync(requestUri, content).Result) | ||
{ | ||
try | ||
{ | ||
response.EnsureSuccessStatusCode(); | ||
|
||
message = converted; | ||
} | ||
catch (HttpRequestException ex) | ||
{ | ||
message = ex.Message; | ||
} | ||
} | ||
|
||
Console.WriteLine($"Message sent: {message}"); | ||
} | ||
|
||
private static string ParseString(string value) | ||
{ | ||
var parsed = string.IsNullOrWhiteSpace(value) | ||
? null | ||
: value; | ||
|
||
return parsed; | ||
} | ||
|
||
private static List<T> ParseCollection<T>(string value) | ||
{ | ||
var parsed = string.IsNullOrWhiteSpace(value) | ||
? null | ||
: JsonConvert.DeserializeObject<List<T>>(value, settings); | ||
|
||
return parsed; | ||
} | ||
} | ||
} |