Skip to content

feat: Flag to use the commit message as the PR title #36

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This also isn't limited to Github Action yaml files - another use case could be
| `PULL_REQUEST` | **false** | Set to `true` if you want the changes to be pushed via pull request. |
| `SKIP_CI` | **false** | Set to `true` if you want skip all automations inside target repository. |
| `COMMIT_MESSAGE` | **false** | You can provide your custom commit message. |
| `COMMIT_MESSAGE_AS_PR_TITLE` | **false** | Use the commit message as the pull request title. |
| `RETRY_MODE` | **true** | Enable retry and throttling octokit plugins to avoid secondary rate limits on github content creation. |

### Personal Access Token Scope
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ inputs:
description: "Provide your own custom commit MESSAGE"
required: false
default: 'false'
COMMIT_MESSAGE_AS_PR_TITLE:
description: "Use the commit message as the pull request title"
required: false
default: 'false'
RETRY_MODE:
description: "Enable retry and throttling octokit plugins to avoid secondary rate limits on github content creation"
required: false
Expand Down
29 changes: 15 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";

async function run() {
let AUTO_CREATE_NEW_BRANCH = require( './variables' ).AUTO_CREATE_NEW_BRANCH;
let COMMIT_EACH_FILE = require( './variables' ).COMMIT_EACH_FILE;
let DRY_RUN = require( './variables' ).DRY_RUN;
let GITHUB_TOKEN = require( './variables' ).GITHUB_TOKEN;
let GIT_URL = require( './variables' ).GIT_URL;
let WORKFLOW_FILES_DIR = require( './variables' ).WORKFLOW_FILES_DIR;
let WORKSPACE = require( './variables' ).WORKSPACE;
let REPOSITORIES = require( './variables' ).REPOSITORIES;
let WORKFLOW_FILES = require( './variables' ).WORKFLOW_FILES;
let PULL_REQUEST = require( './variables' ).PULL_REQUEST;
let SKIP_CI = require( './variables' ).SKIP_CI;
let COMMIT_MESSAGE = require( './variables' ).COMMIT_MESSAGE;
let RETRY_MODE = require( './variables' ).RETRY_MODE;
let AUTO_CREATE_NEW_BRANCH = require( './variables' ).AUTO_CREATE_NEW_BRANCH;
let COMMIT_EACH_FILE = require( './variables' ).COMMIT_EACH_FILE;
let DRY_RUN = require( './variables' ).DRY_RUN;
let GITHUB_TOKEN = require( './variables' ).GITHUB_TOKEN;
let GIT_URL = require( './variables' ).GIT_URL;
let WORKFLOW_FILES_DIR = require( './variables' ).WORKFLOW_FILES_DIR;
let WORKSPACE = require( './variables' ).WORKSPACE;
let REPOSITORIES = require( './variables' ).REPOSITORIES;
let WORKFLOW_FILES = require( './variables' ).WORKFLOW_FILES;
let PULL_REQUEST = require( './variables' ).PULL_REQUEST;
let SKIP_CI = require( './variables' ).SKIP_CI;
let COMMIT_MESSAGE = require( './variables' ).COMMIT_MESSAGE;
let COMMIT_MESSAGE_AS_PR_TITLE = require( './variables' ).COMMIT_MESSAGE_AS_PR_TITLE;
let RETRY_MODE = require( './variables' ).RETRY_MODE;

toolkit.log( '-------------------------------------------------------' );
toolkit.log( '⚙️ Basic Config' );
Expand Down Expand Up @@ -193,7 +194,7 @@ async function run() {
// create the pull request
const pull_request_resp = await finalOctokit.request(`POST /repos/${owner}/${repository}/pulls`, {
owner: owner, repo: repository,
title: `Files Sync From ${toolkit.input.env( 'GITHUB_REPOSITORY' )}`,
title: ( COMMIT_MESSAGE_AS_PR_TITLE ) ? COMMIT_MESSAGE : `Files Sync From ${toolkit.input.env( 'GITHUB_REPOSITORY' )}`,
head: pull_request_branch,
base: current_branch
}).catch((error) => {
Expand Down
34 changes: 18 additions & 16 deletions src/variables.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
const core = require( '@actions/core' );
const toolkit = require( 'actions-js-toolkit' );

const AUTO_CREATE_NEW_BRANCH = toolkit.input.tobool( core.getInput( 'AUTO_CREATE_NEW_BRANCH' ) );
const COMMIT_EACH_FILE = toolkit.input.tobool( core.getInput( 'COMMIT_EACH_FILE' ) );
const DRY_RUN = toolkit.input.tobool( core.getInput( 'DRY_RUN' ) );
const PULL_REQUEST = toolkit.input.tobool( core.getInput( 'PULL_REQUEST' ) );
const SKIP_CI = toolkit.input.tobool( core.getInput( 'SKIP_CI' ) );
const GITHUB_TOKEN = core.getInput( 'GITHUB_TOKEN' );
const GIT_URL = core.getInput( 'GIT_URL' );
const RAW_REPOSITORIES = core.getInput( 'REPOSITORIES' );
const COMMIT_MESSAGE = core.getInput( 'COMMIT_MESSAGE' );
const RAW_WORKFLOW_FILES = core.getInput( 'WORKFLOW_FILES' );
const RETRY_MODE = core.getInput( 'RETRY_MODE' );
const WORKFLOW_FILES_DIR = core.getInput( 'WORKFLOW_FILES_DIR' );
const REPOSITORIES = RAW_REPOSITORIES.split( '\n' );
const WORKFLOW_FILES = RAW_WORKFLOW_FILES.split( '\n' );
const GITHUB_WORKSPACE = toolkit.input.env( 'GITHUB_WORKSPACE' );
const WORKSPACE = toolkit.path.dirname( toolkit.path.dirname( GITHUB_WORKSPACE ) ) + '/workflow-sync/';
const AUTO_CREATE_NEW_BRANCH = toolkit.input.tobool( core.getInput( 'AUTO_CREATE_NEW_BRANCH' ) );
const COMMIT_EACH_FILE = toolkit.input.tobool( core.getInput( 'COMMIT_EACH_FILE' ) );
const DRY_RUN = toolkit.input.tobool( core.getInput( 'DRY_RUN' ) );
const PULL_REQUEST = toolkit.input.tobool( core.getInput( 'PULL_REQUEST' ) );
const SKIP_CI = toolkit.input.tobool( core.getInput( 'SKIP_CI' ) );
const GITHUB_TOKEN = core.getInput( 'GITHUB_TOKEN' );
const GIT_URL = core.getInput( 'GIT_URL' );
const RAW_REPOSITORIES = core.getInput( 'REPOSITORIES' );
const COMMIT_MESSAGE = core.getInput( 'COMMIT_MESSAGE' );
const COMMIT_MESSAGE_AS_PR_TITLE = toolkit.input.tobool( core.getInput( 'COMMIT_MESSAGE_AS_PR_TITLE' ) );
const RAW_WORKFLOW_FILES = core.getInput( 'WORKFLOW_FILES' );
const RETRY_MODE = core.getInput( 'RETRY_MODE' );
const WORKFLOW_FILES_DIR = core.getInput( 'WORKFLOW_FILES_DIR' );
const REPOSITORIES = RAW_REPOSITORIES.split( '\n' );
const WORKFLOW_FILES = RAW_WORKFLOW_FILES.split( '\n' );
const GITHUB_WORKSPACE = toolkit.input.env( 'GITHUB_WORKSPACE' );
const WORKSPACE = toolkit.path.dirname( toolkit.path.dirname( GITHUB_WORKSPACE ) ) + '/workflow-sync/';

module.exports = {
GIT_USER: 'Workflow Sync Bot',
Expand All @@ -36,5 +37,6 @@ module.exports = {
GITHUB_WORKSPACE,
SKIP_CI,
COMMIT_MESSAGE,
COMMIT_MESSAGE_AS_PR_TITLE,
RETRY_MODE
};