Class: GitHub

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

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_url: default_api_url, repository: ENV["GITHUB_REPOSITORY"], server_url: ENV.fetch("GITHUB_SERVER_URL", "https://github.com"), token: default_token, workspace: ENV.fetch("GITHUB_WORKSPACE", Dir.pwd)) ⇒ GitHub

Returns a new instance of GitHub.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/github.rb', line 7

def initialize(
  api_url: default_api_url,
  repository: ENV["GITHUB_REPOSITORY"],
  server_url: ENV.fetch("GITHUB_SERVER_URL", "https://github.com"),
  token: default_token,
  workspace: ENV.fetch("GITHUB_WORKSPACE", Dir.pwd)
)
  @api_url = api_url
  @repository = repository
  @server_url = server_url
  @token = token
  @workspace = workspace
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



5
6
7
# File 'lib/github.rb', line 5

def api_url
  @api_url
end

#repositoryObject (readonly)

Returns the value of attribute repository.



5
6
7
# File 'lib/github.rb', line 5

def repository
  @repository
end

#server_urlObject (readonly)

Returns the value of attribute server_url.



5
6
7
# File 'lib/github.rb', line 5

def server_url
  @server_url
end

#tokenObject (readonly)

Returns the value of attribute token.



5
6
7
# File 'lib/github.rb', line 5

def token
  @token
end

#workspaceObject (readonly)

Returns the value of attribute workspace.



5
6
7
# File 'lib/github.rb', line 5

def workspace
  @workspace
end

Class Method Details

.name_with_owner_from(url) ⇒ Object



26
27
28
29
30
# File 'lib/github.rb', line 26

def name_with_owner_from(url)
  regex = %r{(?<x>(?<scheme>https|ssh)://)?(?<username>git@)?github.com[:|/](?<nwo>\w+/\w+)(?<extension>\.git)?}
  match = url.match(regex)
  match && match["nwo"]
end

Instance Method Details

#create(action) ⇒ Object



21
22
23
# File 'lib/github.rb', line 21

def create(action)
  action.run_against(Dependabot.octokit)
end