Skip to content

Commit

Permalink
feat: #18 - customize COMMIT_MESSAGE
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianjost committed May 21, 2020
1 parent c73332f commit e726a7a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Build](https://github.com/adrianjost/files-sync-action/workflows/Build/badge.svg)](https://github.com/adrianjost/files-sync-action/actions?query=workflow%3ABuild) [![Release](https://github.com/adrianjost/files-sync-action/workflows/Release/badge.svg)](https://github.com/adrianjost/files-sync-action/actions?query=workflow%3ARelease) [![Dependency Status](https://david-dm.org/adrianjost/files-sync-action.svg)](https://david-dm.org/adrianjost/files-sync-action) [![Dependency Status](https://david-dm.org/adrianjost/files-sync-action/dev-status.svg)](https://david-dm.org/adrianjost/files-sync-action?type=dev) ![GitHub contributors](https://img.shields.io/github/contributors/adrianjost/files-sync-action?color=bright-green)


[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=adrianjost/files-sync-action)](https://dependabot.com) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

A Github Action that can sync files from one repository to many others. This action allows a maintainer to define community health files in a single repository and have them synced to all other repositories in the Github organization or beyond. You could sync common GitHub Action Workflows, your LICENSE or any other file you can imagine. Regex is used to select the files. Exclude is currently not supported and it is recommended to use a bot user if possible.
Expand Down Expand Up @@ -31,6 +30,17 @@ Source of truth for all files to sync. If files get added, modified or deleted h

All filpaths start at the repository root without a leading slash. The delimiter between path segments is always a forward slash.

### `COMMIT_MESSAGE`

The commit message that will be used to commit the changed files. Check the README for all interpolation options. You can interpolate values by using placeholders in the form of `%KEY%` where key can be one of the following items:

| key | description |
| ------------- | ------------------------------------------ |
| `SRC_REPO` | The value from the according action input. |
| `TARGET_REPO` | The current repo to commit into |

You need more? Let me know by [opening an issue here](https://github.com/adrianjost/files-sync-action/issues/new). I will do my best to add them.

### `SKIP_DELETE`

Will omit all delete operations for matching files present in `TARGET_REPO` but not existant in `SRC_REPO` if set to `true`. Defaults to `false`.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ branding:
icon: copy
description: Copies files from the action's environment (or any other repo) to many other repos.
inputs:
COMMIT_MESSAGE:
description: |
The commit message that will be used to commit the changed files. Check the README for all interpolation options.
required: false
DRY_RUN:
description: |
Run everything except for the copying, removing and commiting functionality.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const parseMultilineInput = (multilineInput) => {

const context = {
get COMMIT_MESSAGE() {
return `Update file(s) from \"${this.SRC_REPO}\"`;
return (
core.getInput("COMMIT_MESSAGE", { required: false }) ||
`Update file(s) from \"%SRC_REPO%\"`
);
},
DRY_RUN: ["1", "true"].includes(
core.getInput("DRY_RUN", { required: false }).toLowerCase()
Expand Down
19 changes: 17 additions & 2 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ const { parse: porcelainParse } = require("@putout/git-status-porcelain");

const {
GITHUB_TOKEN,
SRC_REPO,
COMMIT_MESSAGE,
GIT_USERNAME,
GIT_EMAIL,
DRY_RUN,
} = require("./context");

const interpolateCommitMessage = (message, data) => {
let newMessage = message;
Object.keys(data).forEach((key) => {
if (key === "COMMIT_MESSAGE") {
return;
}
newMessage = newMessage.replace(new RegExp(`%${key}%`, "g"), data[key]);
});
return newMessage;
};

module.exports = {
init: (repoFullname) => {
const { getRepoPath } = require("./utils").init(repoFullname);
Expand Down Expand Up @@ -55,6 +67,10 @@ module.exports = {
}
logger.info("CHANGES DETECTED");
logger.info("COMMIT CHANGES...");
const commitMessage = interpolateCommitMessage(COMMIT_MESSAGE, {
SRC_REPO: SRC_REPO,
TARGET_REPO: repoFullname,
});
if (!DRY_RUN) {
const output = await execCmd(
[
Expand All @@ -63,8 +79,7 @@ module.exports = {
`git add -A`,
`git status`,
// TODO [#17]: improve commit message to contain more details about the changes
// TODO [#18]: allow customization of COMMIT_MESSAGE
`git commit --message "${COMMIT_MESSAGE}"`,
`git commit --message "${commitMessage}"`,
`git push`,
].join(" && "),
getRepoPath(repoFullname)
Expand Down

0 comments on commit e726a7a

Please sign in to comment.