Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keeps commenting on every push #153

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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