Skip to content

Commit

Permalink
Merge pull request #11 from nabeken/follow-ghe-support
Browse files Browse the repository at this point in the history
Follow ghe support
  • Loading branch information
nabeken authored Jun 25, 2023
2 parents 373b587 + a7d4571 commit 8422f4e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Usage of ./go-github-apps:
Installation ID
-show-insts
show all of the installations for the app
-url string
Full URL for a Github Enterprise installation, example 'https://github.example.com/api/v3'
-version
show version info
```
Expand Down
11 changes: 10 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
description: "Github Apps App ID"
private_key:
description: "Github Apps Private Key"
github_url:
description: "Github API URL, for use with Github Enterprise"
default: "https://api.github.com/"

outputs:
app_github_token:
Expand All @@ -25,6 +28,12 @@ runs:
run: |
T=$(mktemp)
trap "rm -f $T" 1 2 3 15
env GITHUB_PRIV_KEY="${{ inputs.private_key }}" go-github-apps -inst-id ${{ inputs.installation_id }} -app-id ${{ inputs.app_id }} > $T
urlparam=""
if [ -n "${{ inputs.github_url }}" ]; then
urlparam="-url ${{ inputs.github_url }}"
fi
env GITHUB_PRIV_KEY="${{ inputs.private_key }}" go-github-apps -inst-id ${{ inputs.installation_id }} -app-id ${{ inputs.app_id }} $urlparam > $T
echo "github_token=$(cat $T)" >> $GITHUB_OUTPUT
shell: bash
20 changes: 17 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func main() {
export := flag.Bool("export", false, "show token as 'export GITHUB_TOKEN=...'")
showVersion := flag.Bool("version", false, "show version info")
showInsts := flag.Bool("show-insts", false, "show all of the installations for the app")
githubURL := flag.String("url", "https://api.github.com", "specify the base URL for Github API, for use with Github Enterprise. Example: 'https://github.example.com/api/v3'")

origUsage := flag.Usage
flag.Usage = func() {
Expand Down Expand Up @@ -60,7 +61,7 @@ func main() {
os.Exit(1)
}

showInstallations(*appID, []byte(key))
showInstallations(*appID, []byte(key), *githubURL)

return
}
Expand All @@ -77,6 +78,10 @@ func main() {
log.Fatal(err)
}

if githubURL != nil && *githubURL != "" {
itr.BaseURL = *githubURL
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

Expand All @@ -96,13 +101,22 @@ func showExport(token string) {
fmt.Printf("export GITHUB_TOKEN=%s\n", token)
}

func showInstallations(appID int64, key []byte) {
func showInstallations(appID int64, key []byte, githubURL string) {
atr, err := ghinstallation.NewAppsTransport(http.DefaultTransport, appID, key)
if err != nil {
log.Fatal(err)
}

client := github.NewClient(&http.Client{Transport: atr})
var client *github.Client
if githubURL != "" {
atr.BaseURL = githubURL
client, err = github.NewEnterpriseClient(githubURL, githubURL, &http.Client{Transport: atr})
if err != nil {
log.Fatalf("failed creating enterprise client: %v", err)
}
} else {
client = github.NewClient(&http.Client{Transport: atr})
}

opts := &github.ListOptions{
PerPage: 10,
Expand Down

0 comments on commit 8422f4e

Please sign in to comment.