Skip to content

Commit

Permalink
chore: Refactor main.js to simplify input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
strworkstation committed Jul 30, 2024
1 parent ad962a5 commit fd08ac0
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,35 @@ async function run() {
const apiKey = core.getInput('api_key', { required: true })
const repoURL = core.getInput('repo_url', { required: true })
const refName = core.getInput('ref_name', { required: true })
const services = core.getInput('services', { required: true })

let timeStamp = core.getInput('time_stamp')
let custom_stage = core.getInput('stage')

if (!timeStamp) {
timeStamp = new Date().toISOString()
}

if (!custom_stage) {
custom_stage = 'release'
}
const services = core.getInput('services') || ''
const timeStamp = core.getInput('time_stamp') || new Date().toISOString()
const custom_stage = core.getInput('stage') || 'release'

const serviceArray = services.split(',').map(item => item.trim())

core.info(`Create LinearB release metrics for ${serviceArray}`)

const url = 'https://public-api.linearb.io/api/v1/deployments'

const body = {
repo_url: repoURL,
ref_name: refName,
timestamp: timeStamp,
stage: custom_stage
}

if (serviceArray.length > 0) {
body.services = serviceArray
}

const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey
},
body: JSON.stringify({
repo_url: repoURL,
ref_name: refName,
services: serviceArray,
timestamp: timeStamp,
stage: custom_stage
})
body: JSON.stringify(body)
})

if (response.status !== 200) {
Expand Down

0 comments on commit fd08ac0

Please sign in to comment.