Skip to content

Commit 006019b

Browse files
aholstrup1mazhelez
andauthoredDec 10, 2024··
Add support for including a suffix in the Commit message/PR message (microsoft#1351)
Add support for including a suffix in the Commit message/PR message This is useful if you have e.g. the Azure Boards integration set up in your repository. Then you can add "AB#<WorkItemId>" to your commit/PR messages. Currently in BCApps we require a workitem so we have to manually edit the PRs for "Update AL-Go System Files" so it includes the workitem. See for example: microsoft/BCApps#2455 Also related to microsoft#1352 --------- Co-authored-by: Maria Zhelezova <[email protected]>
1 parent 98a79c8 commit 006019b

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed
 

‎Actions/AL-Go-Helper.ps1

+31-1
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ function ReadSettings {
661661
"defaultReleaseMD" = "## Release reference documentation\n\nThis is the generated reference documentation for [{REPOSITORY}](https://github.com/{REPOSITORY}).\n\nYou can use the navigation bar at the top and the table of contents to the left to navigate your documentation.\n\nYou can change this content by creating/editing the **{INDEXTEMPLATERELATIVEPATH}** file in your repository or use the alDoc:defaultReleaseMD setting in your repository settings file (.github/AL-Go-Settings.json)\n\n{RELEASENOTES}"
662662
}
663663
"trustMicrosoftNuGetFeeds" = $true
664+
"commitOptions" = [ordered]@{
665+
"messageSuffix" = ""
666+
"pullRequestAutoMerge" = $false
667+
"pullRequestLabels" = @()
668+
}
664669
"trustedSigning" = [ordered]@{
665670
"Endpoint" = ""
666671
"Account" = ""
@@ -1355,9 +1360,23 @@ function CommitFromNewFolder {
13551360
invoke-git add *
13561361
$status = invoke-git -returnValue status --porcelain=v1
13571362
if ($status) {
1363+
$title = $commitMessage
1364+
1365+
# Add commit message suffix if specified in settings
1366+
$settings = ReadSettings
1367+
if ($settings.commitOptions.messageSuffix) {
1368+
$commitMessage = "$commitMessage / $($settings.commitOptions.messageSuffix)"
1369+
$body = "$body`n$($settings.commitOptions.messageSuffix)"
1370+
}
1371+
13581372
if ($commitMessage.Length -gt 250) {
13591373
$commitMessage = "$($commitMessage.Substring(0,250))...)"
13601374
}
1375+
1376+
if ($title.Length -gt 250) {
1377+
$title = "$($title.Substring(0,250))...)"
1378+
}
1379+
13611380
invoke-git commit --allow-empty -m "$commitMessage"
13621381
$activeBranch = invoke-git -returnValue -silent name-rev --name-only HEAD
13631382
# $branch is the name of the branch to be used when creating a Pull Request
@@ -1377,7 +1396,18 @@ function CommitFromNewFolder {
13771396
}
13781397
invoke-git push -u $serverUrl $branch
13791398
try {
1380-
invoke-gh pr create --fill --head $branch --repo $env:GITHUB_REPOSITORY --base $ENV:GITHUB_REF_NAME --body "$body"
1399+
$prCreateCmd = "invoke-gh pr create --fill --title ""$title"" --head ""$branch"" --repo ""$env:GITHUB_REPOSITORY"" --base ""$ENV:GITHUB_REF_NAME"" --body ""$body"""
1400+
if ($settings.commitOptions.pullRequestLabels) {
1401+
$labels = "$($settings.commitOptions.pullRequestLabels -join ",")"
1402+
Write-Host "Adding labels: $labels"
1403+
$prCreateCmd += " --label ""$labels"""
1404+
}
1405+
1406+
Invoke-Expression $prCreateCmd
1407+
1408+
if ($settings.commitOptions.pullRequestAutoMerge) {
1409+
invoke-gh pr merge --auto --squash --delete-branch
1410+
}
13811411
}
13821412
catch {
13831413
OutputError("GitHub actions are not allowed to create Pull Requests (see GitHub Organization or Repository Actions Settings). You can create the PR manually by navigating to $($env:GITHUB_SERVER_URL)/$($env:GITHUB_REPOSITORY)/tree/$branch")

‎RELEASENOTES.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
### New Repository Settings
77

88
- `useGitSubmodules` can be either `true` or `recursive` if you want to enable Git Submodules in your repository. If your Git submodules resides in a private repository, you need to create a secret called `gitSubmodulesToken` containing a PAT with access to the submodule repositories. Like with all other secrets, you can also create a setting called `gitSubmodulesTokenSecretName` and specify the name of another secret, with these permissions (f.ex. ghTokenWorkflow).
9+
- `commitOptions` - is a structure defining how you want AL-Go to handle automated commits or pull requests coming from AL-Go (e.g. for Update AL-Go System Files). The structure contains the following properties
10+
- `messageSuffix` : A string you want to append to the end of commits/pull requests created by AL-Go. This can be useful if you are using the Azure Boards integration (or similar integration) to link commits to workitems.
11+
- `pullRequestAutoMerge` : A boolean defining whether you want AL-Go pull requests to be set to auto-complete. This will auto-complete the pull requests once all checks are green and all required reviewers have approved.
12+
- `pullRequestLabels` : A list of labels to add to the pull request. The labels need to be created in the repository before they can be applied.
913

1014
### Support for Git submodules
1115

‎Scenarios/settings.md

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ The repository settings are only read from the repository settings file (.github
7979
| <a id="UpdateGitHubGoSystemFilesSchedule"></a>UpdateGitHubGoSystemFilesSchedule | CRON schedule for when Update AL-Go System Files should run. When Update AL-Go System Files runs on a schedule, it uses direct Commit instead of creating a PR. Default is no scheduled run, only manual trigger. Build your CRON string here: [https://crontab.guru](https://crontab.guru). You need to run the Update AL-Go System Files workflow for the schedule to take effect. |
8080
| <a id="buildModes"></a>buildModes | A list of build modes to use when building the AL-Go projects. Every AL-Go project will be built using each build mode. AL-Go ships with the following build modes out of the box:<br /> **Default**: Apps are compiled as they are in the source code.<br />**Clean**: _PreprocessorSymbols_ are enabled when compiling the apps. The values for the symbols correspond to the `cleanModePreprocessorSymbols` setting of the AL-Go project.<br />**Translated**: `TranslationFile` compiler feature is enabled when compiling the apps.<br /><br />It is also possible to specify custom build modes by adding a build mode that is different than 'Default', 'Clean' or 'Translated'. |
8181
| <a id="useGitSubmodules"></a>useGitSubmodules | If your repository is using Git Submodules, you can set the `useGitSubmodules` setting to `"true"` or `"recursive"` in order to use these submodules during build workflows. If `useGitSubmodules` is not set, git submodules are not initialized. If the submodules reside in private repositories, you need to define a `gitSubmodulesToken` secret. Read [this](https://aka.ms/algosecrets#gitSubmodulesToken) for more information. |
82+
| <a id="commitOptions"></a>commitOptions | If you want more control over how AL-Go creates pull requests or commits changes to the repository you can define `commitOptions`. It is a structure defining how you want AL-Go to handle automated commits or pull requests coming from AL-Go (e.g. for Update AL-Go System Files). The structure contains the following properties:<br />`messageSuffix` : A string you want to append to the end of commits/pull requests created by AL-Go. This can be useful if you are using the Azure Boards integration (or similar integration) to link commits to work items. <br />`pullRequestAutoMerge` : A boolean defining whether you want AL-Go pull requests to be set to auto-complete. This will auto-complete the pull requests once all checks are green and all required reviewers have approved.<br /> `pullRequestLabels` : A list of labels to add to the pull request. The labels need to be created in the repository before they can be applied.<br />If you want different behavior in different AL-Go workflows you can add the `commitOptions` setting to your [workflow-specific settings files](https://github.com/microsoft/AL-Go/blob/main/Scenarios/settings.md#where-are-the-settings-located). |
8283

8384
## Advanced settings
8485

0 commit comments

Comments
 (0)
Please sign in to comment.