Skip to content

Commit b687dd8

Browse files
alan910127JounQin
andauthored
fix: keeps commenting on every push (#153)
close #145 --------- Co-authored-by: JounQin <admin@1stg.me>
1 parent 6d19dd5 commit b687dd8

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

.changeset/spicy-buses-wonder.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"changesets-gitlab": patch
3+
---
4+
5+
fix: keeps commenting on every push ~
6+
- close #145, revert #143

src/comment.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
VersionType,
66
} from '@changesets/types'
77
import type { Gitlab } from '@gitbeaker/core'
8-
import type { MergeRequestDiffSchema } from '@gitbeaker/rest'
8+
import type { MergeRequestChangesSchema } from '@gitbeaker/rest'
99
import { captureException } from '@sentry/node'
1010
import { humanId } from 'human-id'
1111
import { markdownTable } from 'markdown-table'
@@ -132,10 +132,10 @@ const getNoteInfo = (api: Gitlab, mrIid: number | string) =>
132132
)
133133

134134
const hasChangesetBeenAdded = async (
135-
allDiffsPromise: Promise<MergeRequestDiffSchema[]>,
135+
changedFilesPromise: Promise<MergeRequestChangesSchema>,
136136
) => {
137-
const allDiffs = await allDiffsPromise
138-
return allDiffs.some(file => {
137+
const changedFiles = await changedFilesPromise
138+
return changedFiles.changes.some(file => {
139139
return (
140140
file.new_file &&
141141
/^\.changeset\/.+\.md$/.test(file.new_path) &&
@@ -169,14 +169,19 @@ export const comment = async () => {
169169
let errFromFetchingChangedFiles = ''
170170
try {
171171
const latestCommitSha = CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
172-
const allDiffsPromise = api.MergeRequests.allDiffs(context.projectId, mrIid)
172+
const changedFilesPromise = api.MergeRequests.showChanges(
173+
context.projectId,
174+
mrIid,
175+
)
173176

174177
const [noteInfo, hasChangeset, { changedPackages, releasePlan }] =
175178
await Promise.all([
176179
getNoteInfo(api, mrIid),
177-
hasChangesetBeenAdded(allDiffsPromise),
180+
hasChangesetBeenAdded(changedFilesPromise),
178181
getChangedPackages({
179-
changedFiles: allDiffsPromise.then(x => x.map(x => x.new_path)),
182+
changedFiles: changedFilesPromise.then(x =>
183+
x.changes.map(x => x.new_path),
184+
),
180185
api,
181186
}).catch((err: unknown) => {
182187
if (err instanceof ValidationError) {

0 commit comments

Comments
 (0)