Skip to content

Commit c7b8464

Browse files
committed
Support coustom commit messages
1 parent 2220b63 commit c7b8464

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Syncs markdown documentation files in a repo to its wiki
1010
| rootDocsFolder | Relative path within the repo to the root documentation folder | No, default is the repo's root |
1111
| convertRootReadmeToHomePage | If true, the `README.md` file at the root of the repo will be renamed to `Home.md` in the wiki so that it is used as the wiki homepage | No, default is false |
1212
| useHeaderForWikiName | If true, will extract the top-line header (denoted by a single `#`) and use that as the wiki page's name. Note: if this results in a name collision the sync will fail | No, default is false and wiki names will be the relative path to the file with `/` converted to `__` (e.g. `path/to/doc.md` becomes `path__to_doc.md`) |
13-
| useHeaderForWikiName | If set, inserts a header at the top of each wiki file with the given format<br/>Supports the following format subsitutions:<br/>- `{sourceFileLink}`: the absolute url to the source file in the repo | No, default will not add a header |
13+
| customWikiFileHeaderFormat | If set, inserts a header at the top of each wiki file with the given format<br/>Supports the following format subsitutions:<br/>- `{sourceFileLink}`: the absolute url to the source file in the repo | No, default will not add a header |
14+
| customCommitMessageFormat | If set, uses the given format for the commit message to the wiki. Useful to correlate changes to the source.<br/>Supports the following format subsitutions:<br/>- `{commitMessage}`: the latest commit message for HEAD<br/>- `{shaFull}`: the full SHA of HEAD<br/>- `{shaShort}`: the short SHA of HEAD | No, default is `"Sync Files"` |
1415

1516
## How it works
1617

action.ps1

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $rootDocsFolder = Get-ActionInput rootDocsFolder
1515
$convertRootReadmeToHomePage = Get-ActionInput convertRootReadmeToHomePage
1616
$useHeaderForWikiName = Get-ActionInput useHeaderForWikiName
1717
$customWikiFileHeaderFormat = Get-ActionInput customWikiFileHeaderFormat
18+
$customCommitMessageFormat = Get-ActionInput customCommitMessageFormat
1819

1920
$repositoryName = $env:GITHUB_REPOSITORY
2021

@@ -23,6 +24,8 @@ $repositoryCloneUrl = "https://[email protected]/$repositoryName"
2324

2425
$wikiRepoDirectory = ($repositoryName -split "/")[-1] + ".wiki"
2526

27+
$sourceRepoDirectory = $pwd.Path
28+
2629
if (-not $defaultBranch)
2730
{
2831
$defaultBranch = git branch --show-current
@@ -258,6 +261,30 @@ Function ProcessWikiFile()
258261
Set-Content -Path $file.FullName -Value $content -Force
259262
}
260263

264+
Function GetWikiCommitMessage()
265+
{
266+
if (-not $customCommitMessageFormat)
267+
{
268+
return "Sync Files"
269+
}
270+
271+
Push-Location $sourceRepoDirectory
272+
273+
$commitMessage = $customCommitMessageFormat
274+
275+
$message = git log -1 --pretty=%B
276+
$commitMessage = $commitMessage -replace "{commitMessage}", $message
277+
278+
$shaFull = git rev-parse HEAD
279+
$commitMessage = $commitMessage -replace "{shaFull}", $shaFull
280+
281+
$shaShort = git rev-parse --short HEAD
282+
$commitMessage = $commitMessage -replace "{shaShort}", $shaShort
283+
284+
Pop-Location
285+
return $commitMessage
286+
}
287+
261288
git config --global user.email "[email protected]"
262289
git config --global user.name "GitHub Action"
263290

@@ -278,8 +305,10 @@ Push-Location ..\$wikiRepoDirectory
278305
Write-ActionInfo "Post-processing wiki files..."
279306
ProcessWikiDirectory
280307

308+
$commitMessage = GetWikiCommitMessage
309+
281310
Write-ActionInfo "Pushing wiki"
282311
git add .
283-
git commit -am "Sync Files"
312+
git commit -am $commitMessage
284313
git push
285314
Pop-Location

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ inputs:
3232
Supports the following format subsitutions:
3333
- {sourceFileLink}: the absolute url to the source file in the repo
3434
required: false
35-
default:
35+
36+
customCommitMessageFormat:
37+
description: |
38+
If set, uses the given format for the commit message to the wiki. Useful to correlate changes to the source.
39+
Supports the following format subsitutions:
40+
- {commitMessage}: the latest commit message for HEAD
41+
- {shaFull}: the full SHA of HEAD
42+
- {shaShort}: the short SHA of HEAD
43+
required: false
3644

3745
branding:
3846
color: purple

0 commit comments

Comments
 (0)