Skip to content

Commit

Permalink
fix: keeps commenting on every push (#153)
Browse files Browse the repository at this point in the history
close #145

---------

Co-authored-by: JounQin <[email protected]>
  • Loading branch information
alan910127 and JounQin committed Dec 4, 2023
1 parent 6d19dd5 commit b687dd8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/spicy-buses-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"changesets-gitlab": patch
---

fix: keeps commenting on every push ~
- close #145, revert #143
19 changes: 12 additions & 7 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
VersionType,
} from '@changesets/types'
import type { Gitlab } from '@gitbeaker/core'
import type { MergeRequestDiffSchema } from '@gitbeaker/rest'
import type { MergeRequestChangesSchema } from '@gitbeaker/rest'
import { captureException } from '@sentry/node'
import { humanId } from 'human-id'
import { markdownTable } from 'markdown-table'
Expand Down Expand Up @@ -132,10 +132,10 @@ const getNoteInfo = (api: Gitlab, mrIid: number | string) =>
)

const hasChangesetBeenAdded = async (
allDiffsPromise: Promise<MergeRequestDiffSchema[]>,
changedFilesPromise: Promise<MergeRequestChangesSchema>,
) => {
const allDiffs = await allDiffsPromise
return allDiffs.some(file => {
const changedFiles = await changedFilesPromise
return changedFiles.changes.some(file => {
return (
file.new_file &&
/^\.changeset\/.+\.md$/.test(file.new_path) &&
Expand Down Expand Up @@ -169,14 +169,19 @@ export const comment = async () => {
let errFromFetchingChangedFiles = ''
try {
const latestCommitSha = CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
const allDiffsPromise = api.MergeRequests.allDiffs(context.projectId, mrIid)
const changedFilesPromise = api.MergeRequests.showChanges(
context.projectId,
mrIid,
)

const [noteInfo, hasChangeset, { changedPackages, releasePlan }] =
await Promise.all([
getNoteInfo(api, mrIid),
hasChangesetBeenAdded(allDiffsPromise),
hasChangesetBeenAdded(changedFilesPromise),
getChangedPackages({
changedFiles: allDiffsPromise.then(x => x.map(x => x.new_path)),
changedFiles: changedFilesPromise.then(x =>
x.changes.map(x => x.new_path),
),
api,
}).catch((err: unknown) => {
if (err instanceof ValidationError) {
Expand Down

0 comments on commit b687dd8

Please sign in to comment.