Skip to content

Commit 05c2df5

Browse files
authored
Modified api_uri to support GitHub Enterprise installations (#163)
1 parent 94fd171 commit 05c2df5

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ julia:
88
- 1.1
99
- 1.2
1010
- 1.3
11+
- 1.4
1112
- nightly
1213
notifications:
1314
email: false

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "GitHub"
22
uuid = "bc5e4493-9b4d-5f90-b8aa-2b2bcaad7a26"
3-
version = "5.1.5"
3+
version = "5.1.6"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Here's a table of contents for this rather lengthy README:
2222

2323
[5. Handling Webhook Events](#handling-webhook-events)
2424

25+
[6. GitHub Enterprise](#github-enterprise)
26+
2527
## Response Types
2628

2729
GitHub's JSON responses are parsed and returned to the caller as types of the form `G<:GitHub.GitHubType`. Here's some useful information about these types:
@@ -507,3 +509,18 @@ end
507509
# Start the listener on localhost at port 8000
508510
GitHub.run(listener, IPv4(127,0,0,1), 8000)
509511
```
512+
513+
## GitHub Enterprise
514+
515+
This library work with github.com, and also with self-hosted github, a.k.a. GitHub Enterprise.
516+
517+
To use it with self-hosted github, you need to create `GitHubWebAPI` structure and pass it to functions when needed.
518+
Following example shows obtaining repository info `private/Package.jl` on github instance with API `https://git.company.com/api/v3`.
519+
520+
```julia
521+
import GitHub
522+
523+
api = GitHub.GitHubWebAPI(HTTP.URI("https://git.company.com/api/v3"))
524+
myauth = GitHub.authenticate(api, ENV["GITHUB_AUTH"])
525+
myrepo = GitHub.repo(env, "private/Package.jl", auth=myauth)
526+
```

src/repositories/repositories.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
open_issues_count::Union{Int, Nothing}
2121
url::Union{HTTP.URI, Nothing}
2222
html_url::Union{HTTP.URI, Nothing}
23+
clone_url::Union{HTTP.URI, Nothing}
24+
ssh_url::Union{HTTP.URI, Nothing}
2325
homepage::Union{HTTP.URI, Nothing}
2426
pushed_at::Union{Dates.DateTime, Nothing}
2527
created_at::Union{Dates.DateTime, Nothing}

src/utils/requests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040
# Default API URIs #
4141
####################
4242

43-
api_uri(api::GitHubWebAPI, path) = merge(api.endpoint, path = path)
43+
api_uri(api::GitHubWebAPI, path) = merge(api.endpoint, path = api.endpoint.path * path)
4444
api_uri(api::GitHubAPI, path) = error("URI retrieval not implemented for this API type")
4545

4646
#######################

test/ghtype_tests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ end
8888
"full_name": "octocat/Hello-World",
8989
"private": false,
9090
"url": "https://api.github.com/repos/octocat/Hello-World",
91+
"ssh_url": "[email protected]:octocat/Hello-World.git",
9192
"language": null,
9293
"pushed_at": "2011-01-26T19:06:43Z",
9394
"permissions": {
@@ -118,6 +119,8 @@ end
118119
HTTP.URI(repo_json["url"]),
119120
nothing,
120121
nothing,
122+
HTTP.URI(repo_json["ssh_url"]),
123+
nothing,
121124
Dates.DateTime(chop(repo_json["pushed_at"])),
122125
nothing,
123126
nothing,
@@ -137,6 +140,7 @@ end
137140
full_name = "octocat/Hello-World",
138141
private = false,
139142
url = "https://api.github.com/repos/octocat/Hello-World",
143+
ssh_url = "[email protected]:octocat/Hello-World.git",
140144
pushed_at = "2011-01-26T19:06:43Z",
141145
permissions = Dict(
142146
"admin" => false,

test/read_only_api_tests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,10 @@ end
214214
exptag = tag(reponame, version; auth=auth)
215215
@test isa(exptag, Tag)
216216
end
217+
218+
@testset "URI constructions" begin
219+
public_gh = GitHub.DEFAULT_API
220+
enterprise_gh = GitHub.GitHubWebAPI(HTTP.URI("https://git.company.com/api/v3"))
221+
@test GitHub.api_uri(public_gh, "/rate_limit") == HTTP.URI("https://api.github.com/rate_limit")
222+
@test GitHub.api_uri(enterprise_gh, "/rate_limit") == HTTP.URI("https://git.company.com/api/v3/rate_limit")
223+
end

0 commit comments

Comments
 (0)