Skip to content

Commit

Permalink
Merge pull request #2080 from mathieubergeron/fix-ms-teams-rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Nov 22, 2021
2 parents 5a1a125 + 40446bc commit af5165e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 155 deletions.
18 changes: 6 additions & 12 deletions plugins/microsoft-teams/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createPost should add more indents to nested lists - 2 spaces 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n- PR [some link](google.com)//n - Another note\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;
exports[`createPost should add title 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes/n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

exports[`createPost should add more indents to nested lists 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n- PR [some link](google.com)//n - Another note\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;
exports[`createPost should call Microsoft Office Teams api 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes/n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

exports[`createPost should add title 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;
exports[`createPost should call Microsoft Office Teams api in env var 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes/n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

exports[`createPost should call Microsoft Office Teams api 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;
exports[`createPost should call Microsoft Office Teams api through http proxy 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes/n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

exports[`createPost should call Microsoft Office Teams api in env var 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;
exports[`createPost should call Microsoft Office Teams api through https proxy 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes/n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

exports[`createPost should call Microsoft Office Teams api through http proxy 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

exports[`createPost should call Microsoft Office Teams api through https proxy 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

exports[`createPost should call Microsoft Office Teams api with minimal config 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

exports[`createPost should remove markdown code types from block 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes//n\`\`\`json//n{ /\\"foo/\\": /\\"bar/\\" }\`\`\`//n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;
exports[`createPost should call Microsoft Office Teams api with minimal config 1`] = `"{\\"@context\\":\\"http://schema.org/extensions\\",\\"@type\\":\\"MessageCard\\",\\"text\\":\\"# My Notes/n- PR [some link](google.com)\\",\\"potentialAction\\":[{\\"@type\\":\\"OpenUri\\",\\"name\\":\\"Learn More\\",\\"targets\\":[{\\"os\\":\\"default\\",\\"uri\\":\\"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*\\"}]}]}"`;

This file was deleted.

63 changes: 4 additions & 59 deletions plugins/microsoft-teams/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { defaultLabels } from "@auto-it/core/dist/semver";
import { execSync } from "child_process";
import createHttpsProxyAgent from "https-proxy-agent";

import MicrosoftTeamsPlugin, { sanitizeMarkdown } from "../src";
import MicrosoftTeamsPlugin from "../src";

const fetchSpy = jest.fn();
// @ts-ignore
Expand Down Expand Up @@ -204,47 +204,7 @@ describe("createPost", () => {

await plugin.createPost(
mockAuto,
sanitizeMarkdown("# My Notes\n- PR [some link](google.com)"),
"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*",
undefined
);

expect(fetchSpy).toHaveBeenCalled();
expect(fetchSpy.mock.calls[0][0]).toBe(
"https://custom-microsoft-url"
);
expect(fetchSpy.mock.calls[0][1].agent).toBeUndefined();
expect(fetchSpy.mock.calls[0][1].body).toMatchSnapshot();
});

test("should add more indents to nested lists", async () => {
const plugin = new MicrosoftTeamsPlugin("https://custom-microsoft-url");

await plugin.createPost(
mockAuto,
sanitizeMarkdown(
"# My Notes\n- PR [some link](google.com)\n - Another note"
),
"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*",
undefined
);

expect(fetchSpy).toHaveBeenCalled();
expect(fetchSpy.mock.calls[0][0]).toBe(
"https://custom-microsoft-url"
);
expect(fetchSpy.mock.calls[0][1].agent).toBeUndefined();
expect(fetchSpy.mock.calls[0][1].body).toMatchSnapshot();
});

test("should add more indents to nested lists - 2 spaces", async () => {
const plugin = new MicrosoftTeamsPlugin("https://custom-microsoft-url");

await plugin.createPost(
mockAuto,
sanitizeMarkdown(
"# My Notes\n- PR [some link](google.com)\n - Another note"
),
"# My Notes\n- PR [some link](google.com)",
"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*",
undefined
);
Expand All @@ -263,7 +223,7 @@ describe("createPost", () => {

await plugin.createPost(
mockAuto,
sanitizeMarkdown("# My Notes\n- PR [some link](google.com)"),
"# My Notes\n- PR [some link](google.com)",
"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*",
createHttpsProxyAgent("mock-url")
);
Expand All @@ -276,28 +236,13 @@ describe("createPost", () => {
expect(fetchSpy.mock.calls[0][1].body).toMatchSnapshot();
});

test("should remove markdown code types from block", async () => {
const plugin = new MicrosoftTeamsPlugin("https://custom-microsoft-url");

await plugin.createPost(
mockAuto,
sanitizeMarkdown(
`# My Notes\n\`\`\`json\n{ "foo": "bar" }\`\`\`\n- PR [some link](google.com)`
),
"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*",
undefined
);

expect(fetchSpy.mock.calls[0][1].body).toMatchSnapshot();
});

test("should call Microsoft Office Teams api through https proxy", async () => {
const plugin = new MicrosoftTeamsPlugin("https://custom-microsoft-url");
process.env.https_proxy = "https-proxy";

await plugin.createPost(
mockAuto,
sanitizeMarkdown("# My Notes\n- PR [some link](google.com)"),
"# My Notes\n- PR [some link](google.com)",
"*<https://git.hub/some/project/releases/v1.0.0|v1.0.0>*",
createHttpsProxyAgent("mock-url")
);
Expand Down
55 changes: 0 additions & 55 deletions plugins/microsoft-teams/__tests__/microsoft-teams.test.ts

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/microsoft-teams/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@
"fp-ts": "^2.5.3",
"https-proxy-agent": "^5.0.0",
"io-ts": "^2.1.2",
"jsesc": "^3.0.2",
"node-fetch": "2.6.1",
"tslib": "2.1.0"
},
"devDependencies": {
"@types/jsesc": "^2.5.1"
}
}
6 changes: 1 addition & 5 deletions plugins/microsoft-teams/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import jsesc from "jsesc";
import createHttpsProxyAgent, { HttpsProxyAgent } from "https-proxy-agent";

import {
Expand All @@ -10,9 +9,6 @@ import {
import fetch from "node-fetch";
import * as t from "io-ts";

/** Microsoft Teams accepts markdown, as long as the content was escaped/serialized to a JSON string first */
export const sanitizeMarkdown = (markdown: string) => jsesc(markdown);

const pluginOptions = t.partial({
/** URL of the mircosoft teams to post to */
url: t.string,
Expand Down Expand Up @@ -127,7 +123,7 @@ export default class MicrosoftTeamsPlugin {

await this.createPost(
auto,
sanitizeMarkdown(releaseNotes),
releaseNotes,
releaseUrl,
agent
);
Expand Down
20 changes: 5 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
integrity sha512-K1kQv1BZVtMXQqdpNZt9Pgh85KwamsWX9gYyq1xG4cpyb+EacfMiNfumrju16piFXanCUrCR0P1DowPjV2qV/A==

"@auto-it/bot-list@link:packages/bot-list":
version "10.30.0"
version "10.32.0"

"@auto-it/core@link:packages/core":
version "10.30.0"
version "10.32.0"
dependencies:
"@auto-it/bot-list" "link:packages/bot-list"
"@endemolshinegroup/cosmiconfig-typescript-loader" "^3.0.2"
Expand Down Expand Up @@ -59,7 +59,7 @@
url-join "^4.0.0"

"@auto-it/npm@link:plugins/npm":
version "10.30.0"
version "10.32.0"
dependencies:
"@auto-it/core" "link:packages/core"
"@auto-it/package-json-utils" "link:packages/package-json-utils"
Expand All @@ -77,13 +77,13 @@
user-home "^2.0.0"

"@auto-it/package-json-utils@link:packages/package-json-utils":
version "10.30.0"
version "10.32.0"
dependencies:
parse-author "^2.0.0"
parse-github-url "1.0.2"

"@auto-it/released@link:plugins/released":
version "10.30.0"
version "10.32.0"
dependencies:
"@auto-it/bot-list" "link:packages/bot-list"
"@auto-it/core" "link:packages/core"
Expand Down Expand Up @@ -2850,11 +2850,6 @@
"@types/parse5" "*"
"@types/tough-cookie" "*"

"@types/jsesc@^2.5.1":
version "2.5.1"
resolved "https://registry.yarnpkg.com/@types/jsesc/-/jsesc-2.5.1.tgz#c34defc608ec94b68dc6a12a581b440942c6d503"
integrity sha512-9VN+6yxLOPLOav+7PwjZbxiID2bVaeq0ED4qSQmdQTdjnXJSaCVKTR58t15oqH1H5t8Ng2ZX1SabJVoN9Q34bw==

"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6":
version "7.0.7"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
Expand Down Expand Up @@ -9278,11 +9273,6 @@ jsesc@^2.5.1:
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4"
integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==

jsesc@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-3.0.2.tgz#bb8b09a6597ba426425f2e4a07245c3d00b9343e"
integrity sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==

jsesc@~0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d"
Expand Down

0 comments on commit af5165e

Please sign in to comment.