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

feat: create MR with custom target branch #70

Merged
merged 7 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/seven-pugs-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'changesets-gitlab': patch
---

merge requests target branch can now be configured through a input environment variable
JounQin marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const main = async ({
script: getOptionalInput('version'),
gitlabToken: GITLAB_TOKEN!,
mrTitle: getOptionalInput('title'),
mrTargetBranch: getOptionalInput('target_branch'),
commitMessage: getOptionalInput('commit'),
hasPublishScript,
})
Expand Down
25 changes: 15 additions & 10 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ interface VersionOptions {
gitlabToken: string
cwd?: string
mrTitle?: string
mrTargetBranch?: string
commitMessage?: string
hasPublishScript?: boolean
}
Expand All @@ -194,17 +195,19 @@ export async function runVersion({
gitlabToken,
cwd = process.cwd(),
mrTitle = 'Version Packages',
mrTargetBranch = context.ref,
commitMessage = 'Version Packages',
hasPublishScript = false,
}: VersionOptions) {
const branch = context.ref
const versionBranch = `changeset-release/${branch}`
const currentBranch = context.ref
const versionBranch = `changeset-release/${currentBranch}`

const api = createApi(gitlabToken)
const { preState } = await readChangesetState(cwd)

await gitUtils.switchToMaybeExistingBranch(versionBranch)
await exec('git', ['fetch', 'origin', branch])
await gitUtils.reset(`origin/${branch}`)
await exec('git', ['fetch', 'origin', currentBranch])
await gitUtils.reset(`origin/${currentBranch}`)

const versionsByDirectory = await getVersionsByDirectory(cwd)

Expand All @@ -228,13 +231,13 @@ export async function runVersion({
hasPublishScript
? 'the packages will be published to npm automatically'
: 'publish to npm yourself or [setup this action to publish automatically](https://github.com/un-ts/changesets-gitlab#with-publishing)'
}. If you're not ready to do a release yet, that's fine, whenever you add more changesets to ${branch}, this MR will be updated.
}. If you're not ready to do a release yet, that's fine, whenever you add more changesets to ${currentBranch}, this MR will be updated.
${
preState
? `
⚠️⚠️⚠️⚠️⚠️⚠️

\`${branch}\` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run \`changeset pre exit\` on \`${branch}\`.
\`${currentBranch}\` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run \`changeset pre exit\` on \`${currentBranch}\`.

⚠️⚠️⚠️⚠️⚠️⚠️
`
Expand Down Expand Up @@ -286,27 +289,29 @@ ${
projectId: context.projectId,
state: 'opened',
sourceBranch: versionBranch,
target_branch: branch,
target_branch: mrTargetBranch,
maxPages: 1,
perPage: 1,
})
console.log(JSON.stringify(searchResult, null, 2))
if (searchResult.length === 0) {
console.log('creating merge request')
console.log(
`Creating merge request from ${versionBranch} to ${mrTargetBranch}.`,
JounQin marked this conversation as resolved.
Show resolved Hide resolved
)
await api.MergeRequests.create(
context.projectId,
versionBranch,
branch,
mrTargetBranch,
finalMrTitle,
{
description: await mrBodyPromise,
},
)
} else {
console.log('Found existing merge request, updating.')
lluiscab marked this conversation as resolved.
Show resolved Hide resolved
await api.MergeRequests.edit(context.projectId, searchResult[0].iid, {
title: finalMrTitle,
description: await mrBodyPromise,
})
console.log('merge request found')
}
}