Skip to content

Commit

Permalink
Add action annotation
Browse files Browse the repository at this point in the history
The annotation describes FlyCI Wingman Action way of work and AI usage as well as it provides a feedback appeal.
  • Loading branch information
n-valchev committed Jul 17, 2024
1 parent e69eda1 commit a799db2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
10 changes: 8 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18899,10 +18899,10 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
command_1.issueCommand("warning", utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
}
exports2.warning = warning;
function notice(message, properties = {}) {
function notice2(message, properties = {}) {
command_1.issueCommand("notice", utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
}
exports2.notice = notice;
exports2.notice = notice2;
function info2(message) {
process.stdout.write(message + os2.EOL);
}
Expand Down Expand Up @@ -22082,6 +22082,12 @@ var generateSuggestions = async (accessToken, wingmanResultPath) => {
// src/action.ts
var run = async () => {
try {
(0, import_core.notice)(
"FlyCI Wingman Action uses a generative AI to fix your build errors by creating suggestions to your pull requests. Join our Discord Community at https://discord.com/invite/JyCjh439da to get help, request features, and share feedback. Alternatively, send us an email at [email protected].",
{
title: "FlyCI Wingman Notice"
}
);
(0, import_core.info)("Obtaining Wingman access token...");
const accessToken = await getAccessToken();
(0, import_node_assert4.default)(accessToken, "Unable to obtain Wingman access token");
Expand Down
24 changes: 14 additions & 10 deletions src/__tests__/action.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setSecret, info, setFailed } from "@actions/core";
import { setSecret, info, setFailed, notice } from "@actions/core";

import { getAccessToken } from "../utils";
import { generateSuggestions } from "../suggestions";
Expand All @@ -9,6 +9,7 @@ jest.mock("@actions/core", () => ({
info: jest.fn(),
setFailed: jest.fn(),
setSecret: jest.fn(),
notice: jest.fn(),
}));

jest.mock("../wingman", () => ({
Expand All @@ -27,10 +28,6 @@ jest.mock("../suggestions", () => ({

describe("wingman action run", () => {
const mockGetAccessToken = getAccessToken as jest.Mock;
const mockGenerateSuggestions = generateSuggestions as jest.Mock;
const mockSetSecret = setSecret as jest.Mock;
const mockInfo = info as jest.Mock;
const mockSetFailed = setFailed as jest.Mock;
const mockDownloadWingmanClient = WingmanClient.download as jest.Mock;

const mockWingmanRun = jest.fn();
Expand All @@ -49,29 +46,36 @@ describe("wingman action run", () => {

await run();

expect(notice).toHaveBeenCalledExactlyOnceWith(
"FlyCI Wingman Action uses a generative AI to fix your build errors by creating suggestions to your pull requests. Join our Discord Community at https://discord.com/invite/JyCjh439da to get help, request features, and share feedback. Alternatively, send us an email at [email protected].",
{
title: "FlyCI Wingman Notice",
},
);

expect(mockGetAccessToken).toHaveBeenCalledOnce();

expect(mockSetSecret).toHaveBeenCalledAfter(mockGetAccessToken);
expect(mockSetSecret).toHaveBeenCalledExactlyOnceWith(accessToken);
expect(setSecret).toHaveBeenCalledAfter(mockGetAccessToken);
expect(setSecret).toHaveBeenCalledExactlyOnceWith(accessToken);

expect(mockDownloadWingmanClient).toHaveBeenCalledExactlyOnceWith(
accessToken,
);

expect(mockGenerateSuggestions).toHaveBeenCalledExactlyOnceWith(
expect(generateSuggestions).toHaveBeenCalledExactlyOnceWith(
accessToken,
resultFilePath,
);

expect(mockInfo).toHaveBeenLastCalledWith("Success!");
expect(info).toHaveBeenLastCalledWith("Success!");
});

it("when unable to obtain access token should set action as failed", async () => {
mockGetAccessToken.mockResolvedValueOnce(undefined);

await run();

expect(mockSetFailed).toHaveBeenCalledExactlyOnceWith(
expect(setFailed).toHaveBeenCalledExactlyOnceWith(
'Wingman: Encountered an expected error "Unable to obtain Wingman access token"',
);
});
Expand Down
8 changes: 7 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import assert from "node:assert";

import { info, setFailed, setSecret } from "@actions/core";
import { info, setFailed, setSecret, notice } from "@actions/core";

import { WingmanClient } from "./wingman";
import { getAccessToken } from "./utils";
import { generateSuggestions } from "./suggestions";

export const run = async (): Promise<void> => {
try {
notice(
"FlyCI Wingman Action uses a generative AI to fix your build errors by creating suggestions to your pull requests. Join our Discord Community at https://discord.com/invite/JyCjh439da to get help, request features, and share feedback. Alternatively, send us an email at [email protected].",
{
title: "FlyCI Wingman Notice",
},
);
info("Obtaining Wingman access token...");
const accessToken = await getAccessToken();

Expand Down

0 comments on commit a799db2

Please sign in to comment.