Add inputs

This commit is contained in:
Nick Cipollo
2019-08-26 16:31:05 -04:00
parent e14d7835e1
commit ce5f096e71
2 changed files with 94 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
import * as core from '@actions/core';
import { Context } from "@actions/github/lib/context";
import { isObject } from 'util';
import { fstat, readFileSync } from 'fs';
export class Inputs {
private context: Context
@@ -8,22 +10,57 @@ export class Inputs {
this.context = context
}
get token(): string {
return core.getInput('token', {required: true})
get artifact(): string {
return core.getInput('artifact')
}
get tag() : string {
get commit(): string {
return core.getInput('commit')
}
get description(): string {
const description = core.getInput('description')
if(description) {
return description
}
const descriptionFile = core.getInput('descriptionFile')
if(descriptionFile) {
return this.stringFromFile(descriptionFile)
}
return ''
}
get name(): string {
const name = core.getInput('tag')
if (name) {
return name
}
return this.tag
}
get token(): string {
return core.getInput('token', { required: true })
}
get tag(): string {
const tag = core.getInput('tag')
if(tag) {
if (tag) {
return tag;
}
const ref = this.context.ref
const tagPath = "refs/tags/"
if(ref && ref.startsWith(tagPath)) {
if (ref && ref.startsWith(tagPath)) {
return ref.substr(tagPath.length, ref.length)
}
throw Error("No tag found in ref or input!")
}
private stringFromFile(path: string): string {
return readFileSync(path, 'utf-8')
}
}