Skip to content

Commit

Permalink
chore: remove once function
Browse files Browse the repository at this point in the history
  • Loading branch information
alan910127 committed Nov 17, 2023
1 parent 71c1ef8 commit d3ad967
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
16 changes: 8 additions & 8 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { setFailed } from '@actions/core'
import dotenv from 'dotenv'

import { once } from './once.js'
import type { Env } from './types'

dotenv.config()

const gitlabTokenGetter = once(() => {
if (!process.env.GITLAB_TOKEN) {
setFailed('Please add the `GITLAB_TOKEN` to the changesets action')
}
return process.env.GITLAB_TOKEN as string
})
let isGitlabTokenValidated = false

export const env = {
...process.env,
Expand All @@ -25,6 +19,12 @@ export const env = {
// only check for the token if we are explicitly using it
// eslint-disable-next-line sonar/function-name
get GITLAB_TOKEN() {
return gitlabTokenGetter()
if (!isGitlabTokenValidated) {
isGitlabTokenValidated = true
if (!process.env.GITLAB_TOKEN) {
setFailed('Please add the `GITLAB_TOKEN` to the changesets action')
}
}
return process.env.GITLAB_TOKEN as string
},
} as Env
21 changes: 0 additions & 21 deletions src/once.ts

This file was deleted.

0 comments on commit d3ad967

Please sign in to comment.