Class: Bard::Github
- Inherits:
-
Struct
- Object
- Struct
- Bard::Github
- Defined in:
- lib/bard/github.rb
Instance Attribute Summary collapse
-
#project_name ⇒ Object
Returns the value of attribute project_name.
Instance Method Summary collapse
- #add_deploy_key(title:, key:) ⇒ Object
- #add_master_branch_protection ⇒ Object
- #add_master_key(master_key) ⇒ Object
- #create_repo ⇒ Object
- #delete(path, params = {}) ⇒ Object
- #delete_repo ⇒ Object
- #encrypt_secret(encoded_public_key, secret) ⇒ Object
- #get(path, params = {}) ⇒ Object
- #patch(path, params = {}) ⇒ Object
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
- #read_file(path, branch: "master") ⇒ Object
Instance Attribute Details
#project_name ⇒ Object
Returns the value of attribute project_name
7 8 9 |
# File 'lib/bard/github.rb', line 7 def project_name @project_name end |
Instance Method Details
#add_deploy_key(title:, key:) ⇒ Object
52 53 54 |
# File 'lib/bard/github.rb', line 52 def add_deploy_key title:, key: post("keys", title:, key:) end |
#add_master_branch_protection ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/bard/github.rb', line 76 def add_master_branch_protection put("branches/master/protection", { required_status_checks: { strict: false, contexts: [], }, enforce_admins: nil, required_pull_request_reviews: nil, restrictions: nil, }) end |
#add_master_key(master_key) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bard/github.rb', line 56 def add_master_key master_key response = get("actions/secrets/public-key") public_key, public_key_id = response.values_at("key", "key_id") def encrypt_secret(encoded_public_key, secret) decoded_key = Base64.decode64(encoded_public_key) public_key = RbNaCl::PublicKey.new(decoded_key) box = RbNaCl::Boxes::Sealed.from_public_key(public_key) encrypted_secret = box.encrypt(secret) Base64.strict_encode64(encrypted_secret) end encrypted_master_key = encrypt_secret(public_key, master_key) put("actions/secrets/RAILS_MASTER_KEY", { encrypted_value: encrypted_master_key, key_id: public_key_id, }) end |
#create_repo ⇒ Object
88 89 90 91 92 93 |
# File 'lib/bard/github.rb', line 88 def create_repo post("https://api.github.com/orgs/botandrosedesign/repos", { name: project_name, private: true, }) end |
#delete(path, params = {}) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/bard/github.rb', line 39 def delete path, params={} request(path) do |uri| Net::HTTP::Delete.new(uri).tap do |r| r.body = JSON.dump(params) end end end |
#delete_repo ⇒ Object
95 96 97 |
# File 'lib/bard/github.rb', line 95 def delete_repo delete(nil) end |
#encrypt_secret(encoded_public_key, secret) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/bard/github.rb', line 60 def encrypt_secret(encoded_public_key, secret) decoded_key = Base64.decode64(encoded_public_key) public_key = RbNaCl::PublicKey.new(decoded_key) box = RbNaCl::Boxes::Sealed.from_public_key(public_key) encrypted_secret = box.encrypt(secret) Base64.strict_encode64(encrypted_secret) end |
#get(path, params = {}) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/bard/github.rb', line 8 def get path, params={} request(path) do |uri| uri.query = URI.encode_www_form(params) Net::HTTP::Get.new(uri) end end |
#patch(path, params = {}) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/bard/github.rb', line 31 def patch path, params={} request(path) do |uri| Net::HTTP::Patch.new(uri).tap do |r| r.body = JSON.dump(params) end end end |
#post(path, params = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/bard/github.rb', line 15 def post path, params={} request(path) do |uri| Net::HTTP::Post.new(uri).tap do |r| r.body = JSON.dump(params) end end end |
#put(path, params = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/bard/github.rb', line 23 def put path, params={} request(path) do |uri| Net::HTTP::Put.new(uri).tap do |r| r.body = JSON.dump(params) end end end |
#read_file(path, branch: "master") ⇒ Object
47 48 49 50 |
# File 'lib/bard/github.rb', line 47 def read_file path, branch: "master" = get("contents/#{path}", ref: branch) Base64.decode64(["content"]) end |