Class: Leash::Integration::GithubClient

Inherits:
Object
  • Object
show all
Defined in:
lib/leash/integration/github.rb

Instance Method Summary collapse

Constructor Details

#initialize(leash) ⇒ GithubClient

Create a new GitHub integration client.

Parameters:

  • leash (Leash::Client)

    the Leash SDK client



11
12
13
# File 'lib/leash/integration/github.rb', line 11

def initialize(leash)
  @leash = leash
end

Instance Method Details

#add_issue_comment(owner, repo, issue_number, body) ⇒ Object

Add a comment to an existing issue

Parameters:

  • owner (String)
  • repo (String)
  • issue_number (Float)
  • body (String)

Returns:

  • (Object)


266
267
268
269
270
271
272
273
274
# File 'lib/leash/integration/github.rb', line 266

def add_issue_comment(owner, repo, issue_number, body)
  params = {
    'owner' => owner,
    'repo' => repo,
    'issue_number' => issue_number,
    'body' => body
  }.compact
  @leash.call('github', 'add_issue_comment', params)
end

#create_branch(owner, repo, branch, from_branch: nil) ⇒ Object

Create a new branch in a GitHub repository

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • branch (String)

    Name for the new branch

  • from_branch (String, nil) (defaults to: nil)

    Optional: source branch to create from (defaults to the repository’s default branch)

Returns:

  • (Object)


176
177
178
179
180
181
182
183
184
# File 'lib/leash/integration/github.rb', line 176

def create_branch(owner, repo, branch, from_branch: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'branch' => branch,
    'from_branch' => from_branch
  }.compact
  @leash.call('github', 'create_branch', params)
end

#create_issue(owner, repo, title, body: nil, assignees: nil, milestone: nil, labels: nil) ⇒ Object

Create a new issue in a GitHub repository

Parameters:

  • owner (String)
  • repo (String)
  • title (String)
  • body (String, nil) (defaults to: nil)
  • assignees (Array, nil) (defaults to: nil)
  • milestone (Float, nil) (defaults to: nil)
  • labels (Array, nil) (defaults to: nil)

Returns:

  • (Object)


116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/leash/integration/github.rb', line 116

def create_issue(owner, repo, title, body: nil, assignees: nil, milestone: nil, labels: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'title' => title,
    'body' => body,
    'assignees' => assignees,
    'milestone' => milestone,
    'labels' => labels
  }.compact
  @leash.call('github', 'create_issue', params)
end

#create_or_update_file(owner, repo, path, content, message, branch, sha: nil) ⇒ Object

Create or update a single file in a GitHub repository

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • path (String)

    Path where to create/update the file

  • content (String)

    Content of the file

  • message (String)

    Commit message

  • branch (String)

    Branch to create/update the file in

  • sha (String, nil) (defaults to: nil)

    SHA of the file being replaced (required when updating existing files)

Returns:

  • (Object)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/leash/integration/github.rb', line 25

def create_or_update_file(owner, repo, path, content, message, branch, sha: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'path' => path,
    'content' => content,
    'message' => message,
    'branch' => branch,
    'sha' => sha
  }.compact
  @leash.call('github', 'create_or_update_file', params)
end

#create_pull_request(owner, repo, title, head, base, body: nil, draft: nil, maintainer_can_modify: nil) ⇒ Object

Create a new pull request in a GitHub repository

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • title (String)

    Pull request title

  • body (String, nil) (defaults to: nil)

    Pull request body/description

  • head (String)

    The name of the branch where your changes are implemented

  • base (String)

    The name of the branch you want the changes pulled into

  • draft (Boolean, nil) (defaults to: nil)

    Whether to create the pull request as a draft

  • maintainer_can_modify (Boolean, nil) (defaults to: nil)

    Whether maintainers can modify the pull request

Returns:

  • (Object)


140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/leash/integration/github.rb', line 140

def create_pull_request(owner, repo, title, head, base, body: nil, draft: nil, maintainer_can_modify: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'title' => title,
    'body' => body,
    'head' => head,
    'base' => base,
    'draft' => draft,
    'maintainer_can_modify' => maintainer_can_modify
  }.compact
  @leash.call('github', 'create_pull_request', params)
end

#create_pull_request_review(owner, repo, pull_number, body, event, commit_id: nil, comments: nil) ⇒ Object

Create a review on a pull request

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • pull_number (Float)

    Pull request number

  • commit_id (String, nil) (defaults to: nil)

    The SHA of the commit that needs a review

  • body (String)

    The body text of the review

  • event (String)

    The review action to perform

  • comments (Array, nil) (defaults to: nil)

    Comments to post as part of the review (specify either position or line, not both)

Returns:

  • (Object)


398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/leash/integration/github.rb', line 398

def create_pull_request_review(owner, repo, pull_number, body, event, commit_id: nil, comments: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'pull_number' => pull_number,
    'commit_id' => commit_id,
    'body' => body,
    'event' => event,
    'comments' => comments
  }.compact
  @leash.call('github', 'create_pull_request_review', params)
end

#create_repository(name, description: nil, private: nil, autoinit: nil) ⇒ Object

Create a new GitHub repository in your account

Parameters:

  • name (String)

    Repository name

  • description (String, nil) (defaults to: nil)

    Repository description

  • private (Boolean, nil) (defaults to: nil)

    Whether the repository should be private

  • autoinit (Boolean, nil) (defaults to: nil)

    Initialize with README.md

Returns:

  • (Object)


60
61
62
63
64
65
66
67
68
# File 'lib/leash/integration/github.rb', line 60

def create_repository(name, description: nil, private: nil, autoinit: nil)
  params = {
    'name' => name,
    'description' => description,
    'private' => private,
    'autoInit' => autoinit
  }.compact
  @leash.call('github', 'create_repository', params)
end

#fork_repository(owner, repo, organization: nil) ⇒ Object

Fork a GitHub repository to your account or specified organization

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • organization (String, nil) (defaults to: nil)

    Optional: organization to fork to (defaults to your personal account)

Returns:

  • (Object)


160
161
162
163
164
165
166
167
# File 'lib/leash/integration/github.rb', line 160

def fork_repository(owner, repo, organization: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'organization' => organization
  }.compact
  @leash.call('github', 'fork_repository', params)
end

#get_file_contents(owner, repo, path, branch: nil) ⇒ Object

Get the contents of a file or directory from a GitHub repository

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • path (String)

    Path to the file or directory

  • branch (String, nil) (defaults to: nil)

    Branch to get contents from

Returns:

  • (Object)


77
78
79
80
81
82
83
84
85
# File 'lib/leash/integration/github.rb', line 77

def get_file_contents(owner, repo, path, branch: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'path' => path,
    'branch' => branch
  }.compact
  @leash.call('github', 'get_file_contents', params)
end

#get_issue(owner, repo, issue_number) ⇒ Object

Get details of a specific issue in a GitHub repository.

Parameters:

  • owner (String)
  • repo (String)
  • issue_number (Float)

Returns:

  • (Object)


337
338
339
340
341
342
343
344
# File 'lib/leash/integration/github.rb', line 337

def get_issue(owner, repo, issue_number)
  params = {
    'owner' => owner,
    'repo' => repo,
    'issue_number' => issue_number
  }.compact
  @leash.call('github', 'get_issue', params)
end

#get_pull_request(owner, repo, pull_number) ⇒ Object

Get details of a specific pull request

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • pull_number (Float)

    Pull request number

Returns:

  • (Object)


352
353
354
355
356
357
358
359
# File 'lib/leash/integration/github.rb', line 352

def get_pull_request(owner, repo, pull_number)
  params = {
    'owner' => owner,
    'repo' => repo,
    'pull_number' => pull_number
  }.compact
  @leash.call('github', 'get_pull_request', params)
end

#get_pull_request_comments(owner, repo, pull_number) ⇒ Object

Get the review comments on a pull request

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • pull_number (Float)

    Pull request number

Returns:

  • (Object)


485
486
487
488
489
490
491
492
# File 'lib/leash/integration/github.rb', line 485

def get_pull_request_comments(owner, repo, pull_number)
  params = {
    'owner' => owner,
    'repo' => repo,
    'pull_number' => pull_number
  }.compact
  @leash.call('github', 'get_pull_request_comments', params)
end

#get_pull_request_files(owner, repo, pull_number) ⇒ Object

Get the list of files changed in a pull request

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • pull_number (Float)

    Pull request number

Returns:

  • (Object)


438
439
440
441
442
443
444
445
# File 'lib/leash/integration/github.rb', line 438

def get_pull_request_files(owner, repo, pull_number)
  params = {
    'owner' => owner,
    'repo' => repo,
    'pull_number' => pull_number
  }.compact
  @leash.call('github', 'get_pull_request_files', params)
end

#get_pull_request_reviews(owner, repo, pull_number) ⇒ Object

Get the reviews on a pull request

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • pull_number (Float)

    Pull request number

Returns:

  • (Object)


500
501
502
503
504
505
506
507
# File 'lib/leash/integration/github.rb', line 500

def get_pull_request_reviews(owner, repo, pull_number)
  params = {
    'owner' => owner,
    'repo' => repo,
    'pull_number' => pull_number
  }.compact
  @leash.call('github', 'get_pull_request_reviews', params)
end

#get_pull_request_status(owner, repo, pull_number) ⇒ Object

Get the combined status of all status checks for a pull request

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • pull_number (Float)

    Pull request number

Returns:

  • (Object)


453
454
455
456
457
458
459
460
# File 'lib/leash/integration/github.rb', line 453

def get_pull_request_status(owner, repo, pull_number)
  params = {
    'owner' => owner,
    'repo' => repo,
    'pull_number' => pull_number
  }.compact
  @leash.call('github', 'get_pull_request_status', params)
end

#list_commits(owner, repo, sha: nil, page: nil, perpage: nil) ⇒ Object

Get list of commits of a branch in a GitHub repository

Parameters:

  • owner (String)
  • repo (String)
  • sha (String, nil) (defaults to: nil)
  • page (Float, nil) (defaults to: nil)
  • perpage (Float, nil) (defaults to: nil)

Returns:

  • (Object)


194
195
196
197
198
199
200
201
202
203
# File 'lib/leash/integration/github.rb', line 194

def list_commits(owner, repo, sha: nil, page: nil, perpage: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'sha' => sha,
    'page' => page,
    'perPage' => perpage
  }.compact
  @leash.call('github', 'list_commits', params)
end

#list_issues(owner, repo, direction: nil, labels: nil, page: nil, per_page: nil, since: nil, sort: nil, state: nil) ⇒ Object

List issues in a GitHub repository with filtering options

Parameters:

  • owner (String)
  • repo (String)
  • direction (String, nil) (defaults to: nil)
  • labels (Array, nil) (defaults to: nil)
  • page (Float, nil) (defaults to: nil)
  • per_page (Float, nil) (defaults to: nil)
  • since (String, nil) (defaults to: nil)
  • sort (String, nil) (defaults to: nil)
  • state (String, nil) (defaults to: nil)

Returns:

  • (Object)


217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/leash/integration/github.rb', line 217

def list_issues(owner, repo, direction: nil, labels: nil, page: nil, per_page: nil, since: nil, sort: nil, state: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'direction' => direction,
    'labels' => labels,
    'page' => page,
    'per_page' => per_page,
    'since' => since,
    'sort' => sort,
    'state' => state
  }.compact
  @leash.call('github', 'list_issues', params)
end

#list_pull_requests(owner, repo, state: nil, head: nil, base: nil, sort: nil, direction: nil, per_page: nil, page: nil) ⇒ Object

List and filter repository pull requests

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • state (String, nil) (defaults to: nil)

    State of the pull requests to return

  • head (String, nil) (defaults to: nil)

    Filter by head user or head organization and branch name

  • base (String, nil) (defaults to: nil)

    Filter by base branch name

  • sort (String, nil) (defaults to: nil)

    What to sort results by

  • direction (String, nil) (defaults to: nil)

    The direction of the sort

  • per_page (Float, nil) (defaults to: nil)

    Results per page (max 100)

  • page (Float, nil) (defaults to: nil)

    Page number of the results

Returns:

  • (Object)


373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/leash/integration/github.rb', line 373

def list_pull_requests(owner, repo, state: nil, head: nil, base: nil, sort: nil, direction: nil, per_page: nil, page: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'state' => state,
    'head' => head,
    'base' => base,
    'sort' => sort,
    'direction' => direction,
    'per_page' => per_page,
    'page' => page
  }.compact
  @leash.call('github', 'list_pull_requests', params)
end

#merge_pull_request(owner, repo, pull_number, commit_title: nil, commit_message: nil, merge_method: nil) ⇒ Object

Merge a pull request

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • pull_number (Float)

    Pull request number

  • commit_title (String, nil) (defaults to: nil)

    Title for the automatic commit message

  • commit_message (String, nil) (defaults to: nil)

    Extra detail to append to automatic commit message

  • merge_method (String, nil) (defaults to: nil)

    Merge method to use

Returns:

  • (Object)


420
421
422
423
424
425
426
427
428
429
430
# File 'lib/leash/integration/github.rb', line 420

def merge_pull_request(owner, repo, pull_number, commit_title: nil, commit_message: nil, merge_method: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'pull_number' => pull_number,
    'commit_title' => commit_title,
    'commit_message' => commit_message,
    'merge_method' => merge_method
  }.compact
  @leash.call('github', 'merge_pull_request', params)
end

#push_files(owner, repo, branch, files, message) ⇒ Object

Push multiple files to a GitHub repository in a single commit

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • branch (String)

    Branch to push to (e.g., ‘main’ or ‘master’)

  • files (Array)

    Array of files to push

  • message (String)

    Commit message

Returns:

  • (Object)


95
96
97
98
99
100
101
102
103
104
# File 'lib/leash/integration/github.rb', line 95

def push_files(owner, repo, branch, files, message)
  params = {
    'owner' => owner,
    'repo' => repo,
    'branch' => branch,
    'files' => files,
    'message' => message
  }.compact
  @leash.call('github', 'push_files', params)
end

#search_code(q, order: nil, page: nil, per_page: nil) ⇒ Object

Search for code across GitHub repositories

Parameters:

  • q (String)
  • order (String, nil) (defaults to: nil)
  • page (Float, nil) (defaults to: nil)
  • per_page (Float, nil) (defaults to: nil)

Returns:

  • (Object)


283
284
285
286
287
288
289
290
291
# File 'lib/leash/integration/github.rb', line 283

def search_code(q, order: nil, page: nil, per_page: nil)
  params = {
    'q' => q,
    'order' => order,
    'page' => page,
    'per_page' => per_page
  }.compact
  @leash.call('github', 'search_code', params)
end

#search_issues(q, order: nil, page: nil, per_page: nil, sort: nil) ⇒ Object

Search for issues and pull requests across GitHub repositories

Parameters:

  • q (String)
  • order (String, nil) (defaults to: nil)
  • page (Float, nil) (defaults to: nil)
  • per_page (Float, nil) (defaults to: nil)
  • sort (String, nil) (defaults to: nil)

Returns:

  • (Object)


301
302
303
304
305
306
307
308
309
310
# File 'lib/leash/integration/github.rb', line 301

def search_issues(q, order: nil, page: nil, per_page: nil, sort: nil)
  params = {
    'q' => q,
    'order' => order,
    'page' => page,
    'per_page' => per_page,
    'sort' => sort
  }.compact
  @leash.call('github', 'search_issues', params)
end

#search_repositories(query, page: nil, perpage: nil) ⇒ Object

Search for GitHub repositories

Parameters:

  • query (String)

    Search query (see GitHub search syntax)

  • page (Float, nil) (defaults to: nil)

    Page number for pagination (default: 1)

  • perpage (Float, nil) (defaults to: nil)

    Number of results per page (default: 30, max: 100)

Returns:

  • (Object)


44
45
46
47
48
49
50
51
# File 'lib/leash/integration/github.rb', line 44

def search_repositories(query, page: nil, perpage: nil)
  params = {
    'query' => query,
    'page' => page,
    'perPage' => perpage
  }.compact
  @leash.call('github', 'search_repositories', params)
end

#search_users(q, order: nil, page: nil, per_page: nil, sort: nil) ⇒ Object

Search for users on GitHub

Parameters:

  • q (String)
  • order (String, nil) (defaults to: nil)
  • page (Float, nil) (defaults to: nil)
  • per_page (Float, nil) (defaults to: nil)
  • sort (String, nil) (defaults to: nil)

Returns:

  • (Object)


320
321
322
323
324
325
326
327
328
329
# File 'lib/leash/integration/github.rb', line 320

def search_users(q, order: nil, page: nil, per_page: nil, sort: nil)
  params = {
    'q' => q,
    'order' => order,
    'page' => page,
    'per_page' => per_page,
    'sort' => sort
  }.compact
  @leash.call('github', 'search_users', params)
end

#update_issue(owner, repo, issue_number, title: nil, body: nil, assignees: nil, milestone: nil, labels: nil, state: nil) ⇒ Object

Update an existing issue in a GitHub repository

Parameters:

  • owner (String)
  • repo (String)
  • issue_number (Float)
  • title (String, nil) (defaults to: nil)
  • body (String, nil) (defaults to: nil)
  • assignees (Array, nil) (defaults to: nil)
  • milestone (Float, nil) (defaults to: nil)
  • labels (Array, nil) (defaults to: nil)
  • state (String, nil) (defaults to: nil)

Returns:

  • (Object)


244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/leash/integration/github.rb', line 244

def update_issue(owner, repo, issue_number, title: nil, body: nil, assignees: nil, milestone: nil, labels: nil, state: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'issue_number' => issue_number,
    'title' => title,
    'body' => body,
    'assignees' => assignees,
    'milestone' => milestone,
    'labels' => labels,
    'state' => state
  }.compact
  @leash.call('github', 'update_issue', params)
end

#update_pull_request_branch(owner, repo, pull_number, expected_head_sha: nil) ⇒ Object

Update a pull request branch with the latest changes from the base branch

Parameters:

  • owner (String)

    Repository owner (username or organization)

  • repo (String)

    Repository name

  • pull_number (Float)

    Pull request number

  • expected_head_sha (String, nil) (defaults to: nil)

    The expected SHA of the pull request’s HEAD ref

Returns:

  • (Object)


469
470
471
472
473
474
475
476
477
# File 'lib/leash/integration/github.rb', line 469

def update_pull_request_branch(owner, repo, pull_number, expected_head_sha: nil)
  params = {
    'owner' => owner,
    'repo' => repo,
    'pull_number' => pull_number,
    'expected_head_sha' => expected_head_sha
  }.compact
  @leash.call('github', 'update_pull_request_branch', params)
end