octokitted 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +5 -0
- data/lib/octokitted/git_plugin.rb +0 -0
- data/lib/octokitted.rb +97 -0
- data/lib/version.rb +7 -0
- data/octokitted.gemspec +32 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b33a0fe5db207ed7676f1cacab5d10eda78112d2ff4e952574eab3890975dc3f
|
4
|
+
data.tar.gz: f8cee9a0d5b35409ad84fef1ee75f696eb9f597133b5333ef757eed628f20767
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0210854b5aa9fe12a2e1038167d74e9924064ed60a7c5c84ac9ee433e637f9e2b317e121b3b0aa64e08a8cec702fd96c28708ea6c6bb85923361d292fc0e8cf6'
|
7
|
+
data.tar.gz: b43739ead97c4ee9ea4b8fdd7bf99e2866bd633bae311bdaf0be29f5a8ca9bc1b4d6bf38f9f0d4fe0e115149c247b626631c42a390db44565b1f1bdbdb3b8dbd
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Grant Birkinbine
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
# octokitted
|
2
|
+
|
3
|
+
[![test](https://github.com/GrantBirki/octokitted/actions/workflows/test.yml/badge.svg)](https://github.com/GrantBirki/octokitted/actions/workflows/test.yml) [![lint](https://github.com/GrantBirki/octokitted/actions/workflows/lint.yml/badge.svg)](https://github.com/GrantBirki/octokitted/actions/workflows/lint.yml) [![CodeQL](https://github.com/GrantBirki/octokitted/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/GrantBirki/octokitted/actions/workflows/codeql-analysis.yml)
|
4
|
+
|
5
|
+
A self-hydrating version of Octokit for usage in CI systems - like GitHub Actions!
|
File without changes
|
data/lib/octokitted.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "octokit"
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
class Octokitted
|
7
|
+
# A Octokitted class to interact with the GitHub API
|
8
|
+
attr_reader :login, :org, :repo, :org_and_repo, :client
|
9
|
+
|
10
|
+
# Initialize the class
|
11
|
+
# :param login: The login to use for GitHubAPI interactions (defaults to the owner of the token)
|
12
|
+
# :param org: The org to use with the Octokitted class
|
13
|
+
# :param repo: The repo to interact with with the Octokitted class
|
14
|
+
# :param token: The token to use to authenticate with the GitHub API
|
15
|
+
# :param logger: The logger to use for logging
|
16
|
+
def initialize(login: nil, org: nil, repo: nil, token: nil, logger: nil)
|
17
|
+
org_and_repo_hash = fetch_org_and_repo
|
18
|
+
@login = login
|
19
|
+
@org = org || org_and_repo_hash[:org]
|
20
|
+
@repo = repo || org_and_repo_hash[:repo]
|
21
|
+
@token = token || fetch_token
|
22
|
+
@client = setup_client
|
23
|
+
@log = logger || setup_logger
|
24
|
+
@org_and_repo = org_and_repo_hash[:org_and_repo]
|
25
|
+
|
26
|
+
@log.debug("Octokitted initialized")
|
27
|
+
@log.debug("login: #{@client.login}")
|
28
|
+
@log.debug("org: #{@org}")
|
29
|
+
@log.debug("repo: #{@repo}")
|
30
|
+
end
|
31
|
+
|
32
|
+
# Setter method for the repo instance variable
|
33
|
+
# :param repo: The repo to set
|
34
|
+
# :return: the new org/repo
|
35
|
+
# Example: gh.repo = "test"
|
36
|
+
def repo=(repo)
|
37
|
+
@repo = repo
|
38
|
+
@org_and_repo = "#{@org}/#{@repo}"
|
39
|
+
@log.debug("updated org/repo: #{@org_and_repo}")
|
40
|
+
end
|
41
|
+
|
42
|
+
# Setter method for the org instance variable
|
43
|
+
# :param org: The org to set
|
44
|
+
# :return: the new org/repo
|
45
|
+
# Example: gh.org = "test"
|
46
|
+
def org=(org)
|
47
|
+
@org = org
|
48
|
+
@org_and_repo = "#{@org}/#{@repo}"
|
49
|
+
@log.debug("updated org/repo: #{@org_and_repo}")
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# construct a logger for the class
|
55
|
+
def setup_logger
|
56
|
+
$stdout.sync = true # don't buffer - flush immediately
|
57
|
+
Logger.new($stdout, level: ENV.fetch("LOG_LEVEL", "INFO").upcase)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Fetch the org and repo from the environment
|
61
|
+
# :return: A hash containing the org and repo, and the org and repo separately
|
62
|
+
def fetch_org_and_repo
|
63
|
+
org_and_repo = ENV.fetch("GITHUB_REPOSITORY", nil)
|
64
|
+
org = nil
|
65
|
+
repo = nil
|
66
|
+
|
67
|
+
org = org_and_repo.split("/").first unless org_and_repo.nil?
|
68
|
+
repo = org_and_repo.split("/").last unless org_and_repo.nil?
|
69
|
+
|
70
|
+
return { org_and_repo:, org:, repo: }
|
71
|
+
end
|
72
|
+
|
73
|
+
# fetch the GitHub token from the environment
|
74
|
+
# :return: The GitHub token
|
75
|
+
def fetch_token
|
76
|
+
# first try to use the OCTOKIT_ACCESS_TOKEN env var if it exists
|
77
|
+
token = ENV.fetch("OCTOKIT_ACCESS_TOKEN", nil) # if running in actions
|
78
|
+
return token unless token.nil?
|
79
|
+
|
80
|
+
# next try to use the GITHUB_TOKEN env var if it exists
|
81
|
+
token = ENV.fetch("GITHUB_TOKEN", nil) # if running in actions
|
82
|
+
return token unless token.nil?
|
83
|
+
|
84
|
+
raise "No GitHub token found"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Setup an Octokit client
|
88
|
+
# :return: An Octokit client
|
89
|
+
def setup_client
|
90
|
+
Octokit::Client.new(
|
91
|
+
access_token: @token,
|
92
|
+
login: @login,
|
93
|
+
page_size: ENV.fetch("OCTOKIT_PER_PAGE", 100)&.to_i,
|
94
|
+
auto_paginate: ENV.fetch("OCTOKIT_AUTO_PAGINATE", true)
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
data/lib/version.rb
ADDED
data/octokitted.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "octokitted"
|
7
|
+
spec.version = Octokitted::Version::VERSION
|
8
|
+
spec.authors = ["Grant Birkinbine"]
|
9
|
+
spec.email = "grant.birkinbine@gmail.com"
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
spec.summary = "A self-hydrating version of Octokit for usage in CI systems - like GitHub Actions!"
|
13
|
+
spec.description = <<~SPEC_DESC
|
14
|
+
A self-hydrating version of Octokit for usage in CI systems - like GitHub Actions!
|
15
|
+
SPEC_DESC
|
16
|
+
|
17
|
+
spec.homepage = "https://github.com/grantbirki/octokitted"
|
18
|
+
spec.metadata = {
|
19
|
+
"source_code_uri" => "https://github.com/grantbirki/octokitted",
|
20
|
+
"documentation_uri" => "https://github.com/grantbirki/octokitted",
|
21
|
+
"bug_tracker_uri" => "https://github.com/grantbirki/octokitted/issues"
|
22
|
+
}
|
23
|
+
|
24
|
+
spec.add_dependency "git", "~> 1.18"
|
25
|
+
spec.add_dependency "octokit", "~> 7.1"
|
26
|
+
|
27
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
28
|
+
|
29
|
+
spec.files = %w[LICENSE README.md octokitted.gemspec]
|
30
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octokitted
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Grant Birkinbine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: octokit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '7.1'
|
41
|
+
description: 'A self-hydrating version of Octokit for usage in CI systems - like GitHub
|
42
|
+
Actions!
|
43
|
+
|
44
|
+
'
|
45
|
+
email: grant.birkinbine@gmail.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- lib/octokitted.rb
|
53
|
+
- lib/octokitted/git_plugin.rb
|
54
|
+
- lib/version.rb
|
55
|
+
- octokitted.gemspec
|
56
|
+
homepage: https://github.com/grantbirki/octokitted
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
source_code_uri: https://github.com/grantbirki/octokitted
|
61
|
+
documentation_uri: https://github.com/grantbirki/octokitted
|
62
|
+
bug_tracker_uri: https://github.com/grantbirki/octokitted/issues
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 3.0.0
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubygems_version: 3.4.10
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: A self-hydrating version of Octokit for usage in CI systems - like GitHub
|
82
|
+
Actions!
|
83
|
+
test_files: []
|