Skip to content

Commit a7824cd

Browse files
author
Pascal Zimmermann
authored
Add GitHub Enterprise support (ad-m#106)
* Add GitHub url and GitHub Enterprise support * Add review improvements * Modify the default value to github.server_url
1 parent 8407731 commit a7824cd

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ With ease:
77
- update new code placed in the repository, e.g. by running a linter on it,
88
- track changes in script results using Git as archive,
99
- publish page using GitHub-Pages,
10+
- push changes to a hosted GitHub Enterprise Server instance,
1011
- mirror changes to a separate repository.
1112

1213
## Usage
@@ -44,6 +45,7 @@ jobs:
4445
| name | value | default | description |
4546
| ---- | ----- | ------- | ----------- |
4647
| github_token | string | `${{ github.token }}` | [GITHUB_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow) <br /> or a repo scoped <br /> [Personal Access Token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token). |
48+
| github_url | string | `${{ github.server_url }}` | Specify the GitHub Enterprise or GitHub url|
4749
| branch | string | (default) | Destination branch to push changes. <br /> Can be passed in using `${{ github.ref }}`. |
4850
| force | boolean | false | Determines if force push is used. |
4951
| tags | boolean | false | Determines if `--tags` is used. |

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ inputs:
99
description: 'GitHub token or PAT token'
1010
required: true
1111
default: ${{ github.token }}
12+
github_url:
13+
description: 'GitHub url or GitHub Enterprise url'
14+
required: true
15+
default: ${{ github.server_url }}
1216
repository:
1317
description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
1418
default: ''

start.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,22 @@ const trim = (value, charlist) => trimLeft(trimRight(value, charlist));
4242
const main = async () => {
4343
let branch = process.env.INPUT_BRANCH;
4444
const repository = trim(process.env.INPUT_REPOSITORY || process.env.GITHUB_REPOSITORY);
45+
const github_url = trim(process.env.INPUT_GITHUB_URL)
4546
if (!branch) {
4647
const headers = {
4748
'User-Agent': 'github.com/ad-m/github-push-action'
4849
};
4950
if (process.env.INPUT_GITHUB_TOKEN) headers.Authorization = `token ${process.env.INPUT_GITHUB_TOKEN}`;
50-
const body = JSON.parse(await get(`https://api.github.com/repos/${repository}`, { headers }))
51+
const api_url = github_url === 'github.com' ? 'api.github.com' : github_url + '/api/v3';
52+
const body = JSON.parse(await get(`https://${api_url}/repos/${repository}`, { headers }))
5153
branch = body.default_branch;
5254
}
5355
await exec('bash', [path.join(__dirname, './start.sh')], {
5456
env: {
5557
...process.env,
5658
INPUT_BRANCH: branch,
5759
INPUT_REPOSITORY: repository,
60+
INPUT_GITHUB_URL: github_url,
5861
}
5962
});
6063
};

start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ fi
2323

2424
cd ${INPUT_DIRECTORY}
2525

26-
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
26+
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${GITHUB_URL}/${REPOSITORY}.git"
2727

2828
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;

0 commit comments

Comments
 (0)