Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from codeclimate/npc/first-cut
Browse files Browse the repository at this point in the history
Finish first cut of action
  • Loading branch information
nporteschaikin committed Jul 29, 2019
2 parents c08ff57 + 83c6a3f commit 185e2a2
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 4 deletions.
40 changes: 39 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const axios_1 = __importDefault(require("axios"));
const fs_1 = require("fs");
const snakecase_keys_1 = __importDefault(require("snakecase-keys"));
const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
const DEPLOYS_URL = process.env.VELOCITY_DEPLOYS_URL || "https://velocity.codeclimate.com/deploys";
const GITHUB_EVENT_PATH = process.env.GITHUB_EVENT_PATH;
const readEvent = () => camelcase_keys_1.default(JSON.parse(fs_1.readFileSync(GITHUB_EVENT_PATH, "utf8")));
const report = (deploy) => axios_1.default.post(DEPLOYS_URL, snakecase_keys_1.default({
branch: deploy.branch,
environment: deploy.environment,
revision: deploy.revision,
version: deploy.version,
repositoryUrl: "foo",
token: process.env.VELOCITY_DEPLOYMENT_TOKEN,
}));
const main = () => {
console.log("Hello world");
try {
const event = readEvent();
report({
revision: process.env.GITHUB_SHA,
branch: process.env.GITHUB_REF,
environment: core.getInput("environment") || (event.deployment || {}).environment,
version: core.getInput("version"),
repositoryUrl: event.repository.webUrl,
});
}
catch (error) {
core.setFailed(error.message);
}
};
main();
90 changes: 90 additions & 0 deletions package-lock.json

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

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
},
"dependencies": {
"@actions/core": "file:toolkit/actions-core-0.0.0.tgz",
"@actions/io": "file:toolkit/actions-io-0.0.0.tgz",
"@actions/exec": "file:toolkit/actions-exec-0.0.0.tgz",
"@actions/tool-cache": "file:toolkit/actions-tool-cache-0.0.0.tgz"
"@actions/io": "file:toolkit/actions-io-0.0.0.tgz",
"@actions/tool-cache": "file:toolkit/actions-tool-cache-0.0.0.tgz",
"axios": "^0.19.0",
"camelcase-keys": "^6.0.0",
"snakecase-keys": "^3.1.0"
},
"devDependencies": {
"@types/node": "^12.6.8",
Expand Down
47 changes: 46 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
import * as core from "@actions/core"
import axios, { AxiosResponse } from "axios"
import { readFileSync } from "fs"
import snake from "snakecase-keys"
import camel from "camelcase-keys"

interface Deploy {
revision: string
branch: string
environment: string | null
version: string | null
repositoryUrl: string
}

const DEPLOYS_URL: string =
process.env.VELOCITY_DEPLOYS_URL || "https://velocity.codeclimate.com/deploys"

const GITHUB_EVENT_PATH: string = process.env.GITHUB_EVENT_PATH as string
const readEvent = (): any =>
camel(JSON.parse(readFileSync(GITHUB_EVENT_PATH, "utf8")))

const report = (deploy: Deploy): Promise<AxiosResponse<any>> =>
axios.post(
DEPLOYS_URL,
snake({
branch: deploy.branch,
environment: deploy.environment,
revision: deploy.revision,
version: deploy.version,
repositoryUrl: "foo",
token: process.env.VELOCITY_DEPLOYMENT_TOKEN,
})
)

const main = (): void => {
console.log("Hello world")
try {
const event = readEvent()

report({
revision: process.env.GITHUB_SHA as string,
branch: process.env.GITHUB_REF as string,
environment:
core.getInput("environment") || (event.deployment || {}).environment,
version: core.getInput("version"),
repositoryUrl: event.repository.webUrl,
})
} catch (error) {
core.setFailed(error.message)
}
}

main()

0 comments on commit 185e2a2

Please sign in to comment.