un-ts / changesets-gitlab

GitLab CI cli for changesets like its GitHub Action.
https://opencollective.com/unts/projects/changesets-gitlab
MIT License
86 stars 33 forks source link

Clarify internal usage of environment variables with an exported `env` variable #141

Closed alan910127 closed 10 months ago

alan910127 commented 10 months ago

Description

Currently, environment variables are used in several places in the project to determine the behavior. However, it might be unclear for developers who are new to this codebase whether an environment variable is defined or not. It should be helpful to have an exported env variable with the "actual" types for the variables or even with pre-validation.

Proposed Solution

We could either use:

  1. a separate module, or
  2. a validation library like zod

to validate the environment variables and export the object.

JounQin commented 10 months ago

Isn't a simple export const envs = process.env as Env be fine enough?

alan910127 commented 10 months ago

I think there are some validations inside the logic right now (e.g. check for null), if we simply use type assertions, it might be pretty easy to forget to check them.

JounQin commented 10 months ago

Only GITLAB_TOKEN env is required and well documented, I don't think that worth a validation.

alan910127 commented 10 months ago

If you think the type of environment variables is nice to have, I can go and implement it with option 1. 😄

JounQin commented 10 months ago

Sure, thanks for doing this!