Skip to content

Commit f146e08

Browse files
committed
chore: tiny improvements
1 parent 26af50c commit f146e08

File tree

6 files changed

+28
-34
lines changed

6 files changed

+28
-34
lines changed

.changeset/mighty-chefs-serve.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
'changesets-gitlab': minor
2+
"changesets-gitlab": minor
33
---
44

5-
fetch the tags and push each one individually
5+
feat: fetch the tags and push each one individually

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ GitLab CI cli for [changesets](https://github.com/atlassian/changesets) like its
3131
- `INPUT_TARGET_BRANCH` -> The merge request target branch. Defaults to current branch
3232
- `INPUT_CREATE_GITLAB_RELEASES` - A boolean value to indicate whether to create Gitlab releases after publish or not. Default true.
3333
- `INPUT_LABELS` - A comma separated string of labels to be added to the version package Gitlab Merge request
34-
- `INPUT_PUSH_ALL_TAGS` - A boolean value to indicate whether to push all tags at once using `git push origin --tags` [see](https://github.com/un-ts/changesets-gitlab/issues/194). Default true.
34+
- `INPUT_PUSH_ALL_TAGS` - A boolean value to indicate whether to push all tags at once using `git push origin --tags`, see [#194](https://github.com/un-ts/changesets-gitlab/issues/194) for details. Default true.
3535

3636
### Outputs
3737

src/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { runPublish, runVersion } from './run.js'
1212
import type { MainCommandOptions } from './types.js'
1313
import {
1414
execSync,
15+
FALSY_VALUES,
1516
getOptionalInput,
1617
getUsername,
1718
TRUTHY_VALUES,
@@ -84,8 +85,10 @@ export const main = async ({
8485
const result = await runPublish({
8586
script: publishScript,
8687
gitlabToken: GITLAB_TOKEN,
87-
createGitlabReleases: getInput('create_gitlab_releases') !== 'false',
88-
pushAllTags: getInput('push_all_tags') !== 'false',
88+
createGitlabReleases: !FALSY_VALUES.has(
89+
getInput('create_gitlab_releases'),
90+
),
91+
pushAllTags: !FALSY_VALUES.has(getInput('push_all_tags')),
8992
})
9093

9194
if (result.published) {

src/read-changeset-state.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import { readPreState } from '@changesets/pre'
2-
import _readChangesets from '@changesets/read'
2+
import readChangesets from '@changesets/read'
33
import type { PreState, NewChangeset } from '@changesets/types'
44

55
export interface ChangesetState {
66
preState: PreState | undefined
77
changesets: NewChangeset[]
88
}
99

10-
// @ts-expect-error - workaround for https://github.com/atlassian/changesets/issues/622
11-
const readChangesets = (_readChangesets.default ||
12-
_readChangesets) as typeof _readChangesets
13-
1410
export default async function readChangesetState(
1511
cwd: string = process.cwd(),
1612
): Promise<ChangesetState> {

src/run.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
sortTheThings,
2323
} from './utils.js'
2424

25-
const createRelease = async (
25+
export const createRelease = async (
2626
api: Gitlab,
2727
{ pkg, tagName }: { pkg: Package; tagName: string },
2828
) => {
@@ -55,27 +55,22 @@ const createRelease = async (
5555
}
5656
}
5757

58-
interface PublishOptions {
58+
export interface PublishOptions {
5959
script: string
6060
gitlabToken: string
6161
createGitlabReleases?: boolean
6262
pushAllTags?: boolean
6363
cwd?: string
6464
}
6565

66-
interface PublishedPackage {
66+
export interface PublishedPackage {
6767
name: string
6868
version: string
6969
}
7070

71-
type PublishResult =
72-
| {
73-
published: false
74-
}
75-
| {
76-
published: true
77-
publishedPackages: PublishedPackage[]
78-
}
71+
export type PublishResult =
72+
| { published: false }
73+
| { published: true; publishedPackages: PublishedPackage[] }
7974

8075
// eslint-disable-next-line sonarjs/cognitive-complexity
8176
export async function runPublish({
@@ -116,16 +111,12 @@ export async function runPublish({
116111

117112
if (match) {
118113
releasedPackages.push(pkg)
114+
const tagName = `v${pkg.packageJson.version}`
119115
if (!pushAllTags) {
120-
await gitUtils.pushTag(
121-
`${pkg.packageJson.name}@${pkg.packageJson.version}`,
122-
)
116+
await gitUtils.pushTag(tagName)
123117
}
124118
if (createGitlabReleases) {
125-
await createRelease(api, {
126-
pkg,
127-
tagName: `v${pkg.packageJson.version}`,
128-
})
119+
await createRelease(api, { pkg, tagName })
129120
}
130121
break
131122
}
@@ -151,11 +142,13 @@ export async function runPublish({
151142
releasedPackages.push(pkg)
152143
}
153144
if (!pushAllTags) {
154-
for (const pkg of releasedPackages) {
155-
await gitUtils.pushTag(
156-
`${pkg.packageJson.name}@${pkg.packageJson.version}`,
157-
)
158-
}
145+
await Promise.all(
146+
releasedPackages.map(pkg =>
147+
gitUtils.pushTag(
148+
`${pkg.packageJson.name}@${pkg.packageJson.version}`,
149+
),
150+
),
151+
)
159152
}
160153
if (createGitlabReleases) {
161154
await Promise.all(
@@ -197,7 +190,7 @@ const requireChangesetsCliPkgJson = (cwd: string) => {
197190
}
198191
}
199192

200-
interface VersionOptions {
193+
export interface VersionOptions {
201194
script?: string
202195
gitlabToken: string
203196
cwd?: string

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,6 @@ export const getUsername = (api: Gitlab) => {
172172
export const cjsRequire =
173173
typeof require === 'undefined' ? createRequire(import.meta.url) : require
174174

175+
export const FALSY_VALUES = new Set(['false', '0'])
176+
175177
export const TRUTHY_VALUES = new Set(['true', '1'])

0 commit comments

Comments
 (0)