Skip to content

Commit 694e694

Browse files
authored
Add GitHub Enterprise support (ad-m#108)
* * Add GitHub url and GitHub Enterprise support * Update the GitHub action * Update build.yml Remove push command * Update the PR and remove the test mode * Delete build-pr.yml * Update README.md
1 parent 887c31b commit 694e694

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: Action CI
22

33
on:
4-
pull_request_target:
5-
types:
6-
- opened
7-
branches: [master, main]
84
push:
95
branches: [master, main]
106

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,23 @@ 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_protocol = trim(process.env.INPUT_GITHUB_URL).split("//")[0];
46+
const github_url = trim(process.env.INPUT_GITHUB_URL).split("//")[1];
4547
if (!branch) {
4648
const headers = {
4749
'User-Agent': 'github.com/ad-m/github-push-action'
4850
};
4951
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 }))
52+
const body = JSON.parse(await get(`${process.env.GITHUB_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_PROTOCOL: github_url_protocol,
61+
INPUT_GITHUB_URL: github_url,
5862
}
5963
});
6064
};

start.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ fi
2323

2424
cd ${INPUT_DIRECTORY}
2525

26-
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
27-
26+
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
2827
git config --local --add safe.directory ${INPUT_DIRECTORY}
2928

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

0 commit comments

Comments
 (0)