Skip to content

Commit 3d3935f

Browse files
authored
Add docstrings to pre-existing public API elements (#77)
PR #72 (gist API) added docstrings to all new public types and methods, leaving the pre-existing API undocumented. This adds docstrings to all pre-existing public classes, primitives, actors, and their public methods to bring the entire library to a consistent documentation standard. Also replaces the placeholder package docstring with a proper overview that guides users to the GitHub entry point and explains the Promise-based return pattern. The request/ subpackage is excluded — it's intended to be extracted to its own library and will be documented separately. Closes #74
1 parent 3c0849d commit 3d3935f

20 files changed

Lines changed: 274 additions & 1 deletion

github_rest_api/asset.pony

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use "json"
22
use req = "request"
33

44
class val Asset
5+
"""
6+
A file attached to a GitHub release. Contains the asset's metadata including
7+
its name, size, download count, and the browser download URL.
8+
"""
59
let _creds: req.Credentials
610

711
let id: I64
@@ -50,6 +54,9 @@ class val Asset
5054
browser_download_url = browser_download_url'
5155

5256
primitive AssetJsonConverter is req.JsonConverter[Asset]
57+
"""
58+
Converts a JSON object into an Asset.
59+
"""
5360
fun apply(json: JsonNav, creds: req.Credentials): Asset ? =>
5461
let id = json("id").as_i64()?
5562
let node_id = json("node_id").as_string()?

github_rest_api/commit.pony

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use ut = "uri/template"
66
type CommitOrError is (Commit | req.RequestError)
77

88
class val Commit
9+
"""
10+
A GitHub commit, containing its SHA, changed files, and nested git commit
11+
data (author, committer, message).
12+
"""
913
let _creds: req.Credentials
1014
let sha: String
1115
let files: Array[CommitFile] val
@@ -31,6 +35,9 @@ class val Commit
3135
comments_url = comments_url'
3236

3337
primitive GetCommit
38+
"""
39+
Fetches a single commit by owner, repo, and SHA.
40+
"""
3441
fun apply(owner: String,
3542
repo: String,
3643
sha: String,
@@ -65,6 +72,9 @@ primitive GetCommit
6572
p
6673

6774
primitive CommitJsonConverter is req.JsonConverter[Commit]
75+
"""
76+
Converts a JSON object from the commits API into a Commit.
77+
"""
6878
fun apply(json: JsonNav, creds: req.Credentials): Commit ? =>
6979
let sha = json("sha").as_string()?
7080

github_rest_api/commit_file.pony

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use "promises"
33
use req = "request"
44

55
class val CommitFile
6+
"""
7+
A file changed in a commit, with its SHA, modification status, and filename.
8+
"""
69
let _creds: req.Credentials
710
let sha: String
811
let status: String
@@ -19,6 +22,9 @@ class val CommitFile
1922
filename = filename'
2023

2124
primitive CommitFileJsonConverter is req.JsonConverter[CommitFile]
25+
"""
26+
Converts a JSON object into a CommitFile.
27+
"""
2228
fun apply(json: JsonNav,
2329
creds: req.Credentials): CommitFile ?
2430
=>

github_rest_api/git_commit.pony

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ use "json"
22
use req = "request"
33

44
class val GitCommit
5+
"""
6+
The git commit data within a GitHub commit, containing author, committer,
7+
message, and the git-level URL. This is the nested `commit` object inside the
8+
top-level Commit response.
9+
"""
510
let _creds: req.Credentials
611
let author: GitPerson
712
let committer: GitPerson
@@ -21,6 +26,9 @@ class val GitCommit
2126
url = url'
2227

2328
primitive GitCommitJsonConverter is req.JsonConverter[GitCommit]
29+
"""
30+
Converts a JSON object into a GitCommit.
31+
"""
2432
fun apply(json: JsonNav, creds: req.Credentials): GitCommit ? =>
2533
let author = GitPersonJsonConverter(json("author"), creds)?
2634
let committer = GitPersonJsonConverter(json("committer"), creds)?

github_rest_api/git_person.pony

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use "json"
22
use req = "request"
33

44
class val GitPerson
5+
"""
6+
A git author or committer identity with a name and email address.
7+
"""
58
let name: String
69
let email: String
710

@@ -10,6 +13,9 @@ class val GitPerson
1013
email = email'
1114

1215
primitive GitPersonJsonConverter is req.JsonConverter[GitPerson]
16+
"""
17+
Converts a JSON object into a GitPerson.
18+
"""
1319
fun apply(json: JsonNav, creds: req.Credentials): GitPerson ? =>
1420
let name = json("name").as_string()?
1521
let email = json("email").as_string()?

github_rest_api/github.pony

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ use req = "request"
55
type RepositoryOrError is (Repository | req.RequestError)
66

77
class val GitHub
8+
"""
9+
Entry point for all GitHub REST API operations. Holds credentials and
10+
authentication context used to issue requests. Each method corresponds to a
11+
top-level API operation; returned models provide convenience methods for
12+
further related calls.
13+
"""
814
let _creds: req.Credentials
915

1016
new val create(creds: req.Credentials) =>
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
"""
2-
Package documentation goes here
2+
A Pony library for interacting with the GitHub REST API.
3+
4+
Start by creating a `GitHub` instance with your credentials, then use its
5+
methods to fetch repositories, issues, gists, and other resources. All API
6+
operations return `Promise`-based results as `(Model | RequestError)` unions.
7+
8+
```pony
9+
use "github_rest_api"
10+
use "github_rest_api/request"
11+
12+
let creds = Credentials(auth, "your-token-here")
13+
let github = GitHub(creds)
14+
github.get_repo("ponylang", "ponyc")
15+
```
16+
17+
Returned model objects provide convenience methods for related API calls —
18+
for example, a `Repository` can create labels and releases, and an `Issue`
19+
can create comments.
320
"""

github_rest_api/issue.pony

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ use ut = "uri/template"
66
type IssueOrError is (Issue | req.RequestError)
77

88
class val Issue
9+
"""
10+
A GitHub issue. Provides convenience methods to create comments and list
11+
existing comments on this issue. The `pull_request` field is present when the
12+
issue is actually a pull request.
13+
"""
914
let _creds: req.Credentials
1015

1116
let number: I64
@@ -55,12 +60,21 @@ class val Issue
5560
pull_request = pull_request'
5661

5762
fun create_comment(comment: String): Promise[IssueCommentOrError] =>
63+
"""
64+
Creates a new comment on this issue.
65+
"""
5866
CreateIssueComment.by_url(comments_url, comment, _creds)
5967

6068
fun get_comments(): Promise[IssueCommentsOrError] =>
69+
"""
70+
Fetches all comments on this issue.
71+
"""
6172
GetIssueComments.by_url(comments_url, _creds)
6273

6374
primitive GetIssue
75+
"""
76+
Fetches a single issue by owner, repo, and number.
77+
"""
6478
fun apply(owner: String,
6579
repo: String,
6680
number: I64,
@@ -95,6 +109,10 @@ primitive GetIssue
95109
p
96110

97111
primitive GetRepositoryIssues
112+
"""
113+
Lists issues in a repository as a paginated list, optionally filtered by
114+
labels and state.
115+
"""
98116
fun apply(owner: String,
99117
repo: String,
100118
creds: req.Credentials,
@@ -141,6 +159,9 @@ primitive GetRepositoryIssues
141159

142160

143161
primitive IssueJsonConverter is req.JsonConverter[Issue]
162+
"""
163+
Converts a JSON object from the issues API into an Issue.
164+
"""
144165
fun apply(json: JsonNav, creds: req.Credentials): Issue ? =>
145166
let url = json("url").as_string()?
146167
let respository_url = json("repository_url").as_string()?

github_rest_api/issue_comment.pony

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ type IssueComments is Array[IssueComment] val
99
type IssueCommentsOrError is (IssueComments | req.RequestError)
1010

1111
class val IssueComment
12+
"""
13+
A comment on a GitHub issue.
14+
"""
1215
let _creds: req.Credentials
1316
let body: String
1417
let url: String
@@ -28,6 +31,9 @@ class val IssueComment
2831
issue_url = issue_url'
2932

3033
primitive CreateIssueComment
34+
"""
35+
Creates a new comment on an issue.
36+
"""
3137
fun apply(owner: String,
3238
repo: String,
3339
number: I64,
@@ -68,6 +74,9 @@ primitive CreateIssueComment
6874
p
6975

7076
primitive GetIssueComments
77+
"""
78+
Fetches all comments on an issue.
79+
"""
7180
fun apply(owner: String,
7281
repo: String,
7382
number: I64,
@@ -102,6 +111,10 @@ primitive GetIssueComments
102111
p
103112

104113
primitive IssueCommentsURL
114+
"""
115+
Builds the URL for an issue's comments endpoint from owner, repo, and issue
116+
number.
117+
"""
105118
fun apply(owner: String, repo: String, number: I64)
106119
: (String | ut.URITemplateParseError)
107120
=>
@@ -118,6 +131,9 @@ primitive IssueCommentsURL
118131
end
119132

120133
primitive IssueCommentJsonConverter is req.JsonConverter[IssueComment]
134+
"""
135+
Converts a JSON object into an IssueComment.
136+
"""
121137
fun apply(json: JsonNav,
122138
creds: req.Credentials): IssueComment ?
123139
=>
@@ -129,6 +145,9 @@ primitive IssueCommentJsonConverter is req.JsonConverter[IssueComment]
129145
IssueComment(creds, body, url, html_url, issue_url)
130146

131147
primitive IssueCommentsJsonConverter is req.JsonConverter[Array[IssueComment] val]
148+
"""
149+
Converts a JSON array of issue comment objects into an Array of IssueComment.
150+
"""
132151
fun apply(json: JsonNav,
133152
creds: req.Credentials): Array[IssueComment] val ?
134153
=>

github_rest_api/issue_pull_request.pony

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class val IssuePullRequest
2929
merged_at = merged_at'
3030

3131
primitive IssuePullRequestJsonConverter is req.JsonConverter[IssuePullRequest]
32+
"""
33+
Converts a JSON object into an IssuePullRequest.
34+
"""
3235
fun apply(json: JsonNav, creds: req.Credentials): IssuePullRequest ? =>
3336
let url = json("url").as_string()?
3437
let html_url = json("html_url").as_string()?

0 commit comments

Comments
 (0)