Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: keeps commenting on every push
  • Loading branch information
alan910127 committed Dec 4, 2023
commit 90790780829892f58bcdfe138a409d8268938f22
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