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: deprecation warning in the comment command
  • Loading branch information
alan910127 committed Nov 23, 2023
commit fd4faaccaa7b2d1f0282ee7db99f7f6dd122ddb2
22 changes: 8 additions & 14 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type {
ReleasePlan,
VersionType,
} from '@changesets/types'
import type { Gitlab, MergeRequests } from '@gitbeaker/core'
import type { Gitlab } from '@gitbeaker/core'
import type { MergeRequestDiffSchema } from '@gitbeaker/rest'
import { captureException } from '@sentry/node'
import { humanId } from 'human-id'
import { markdownTable } from 'markdown-table'
Expand Down Expand Up @@ -131,12 +132,10 @@ const getNoteInfo = (api: Gitlab, mrIid: number | string) =>
)

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

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