dependabot-gitea 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e6d7fd6fe0ae143b41ac4cf21feab6f6b9ccd83950f31cd594a29879fae860bc
4
+ data.tar.gz: fc9035d5108bd7b373a84e126126c2d79b9df8db3553a36be341ecb89407be0f
5
+ SHA512:
6
+ metadata.gz: 2da5114f7220e8cd0c6f416fa4fc5bf9989f9a1566584f308feadddcd3f7b56636790ecd7ada243b1d030c687069593c230c506111757740e1b9ae1f14142976
7
+ data.tar.gz: 81f49638bfdc6c0d03576287cfb93b7fe6c7f71509b9f0192dc1c57725db4a638514bdb7df65af4a8dcef8973647de6ac340b84b7adc293cef3df1b581911d25
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dependabot-gitea.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,162 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dependabot-gitea (0.1.0)
5
+ dependabot-omnibus
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.0)
13
+ aws-eventstream (1.0.3)
14
+ aws-partitions (1.269.0)
15
+ aws-sdk-codecommit (1.30.0)
16
+ aws-sdk-core (~> 3, >= 3.71.0)
17
+ aws-sigv4 (~> 1.1)
18
+ aws-sdk-core (3.89.1)
19
+ aws-eventstream (~> 1.0, >= 1.0.2)
20
+ aws-partitions (~> 1, >= 1.239.0)
21
+ aws-sigv4 (~> 1.1)
22
+ jmespath (~> 1.0)
23
+ aws-sdk-ecr (1.24.0)
24
+ aws-sdk-core (~> 3, >= 3.71.0)
25
+ aws-sigv4 (~> 1.1)
26
+ aws-sigv4 (1.1.0)
27
+ aws-eventstream (~> 1.0, >= 1.0.2)
28
+ citrus (3.0.2)
29
+ commonmarker (0.20.2)
30
+ ruby-enum (~> 0.5)
31
+ concurrent-ruby (1.1.5)
32
+ dependabot-bundler (0.116.3)
33
+ dependabot-common (= 0.116.3)
34
+ dependabot-cargo (0.116.3)
35
+ dependabot-common (= 0.116.3)
36
+ dependabot-common (0.116.3)
37
+ aws-sdk-codecommit (~> 1.28)
38
+ aws-sdk-ecr (~> 1.5)
39
+ bundler (>= 1.16, < 3.0.0)
40
+ commonmarker (~> 0.20.1)
41
+ docker_registry2 (~> 1.7, >= 1.7.1)
42
+ excon (~> 0.66)
43
+ gitlab (= 4.13.1)
44
+ nokogiri (~> 1.8)
45
+ octokit (~> 4.6)
46
+ pandoc-ruby (~> 2.0)
47
+ parseconfig (~> 1.0)
48
+ parser (~> 2.5)
49
+ toml-rb (>= 1.1.2, < 3.0)
50
+ dependabot-composer (0.116.3)
51
+ dependabot-common (= 0.116.3)
52
+ dependabot-dep (0.116.3)
53
+ dependabot-common (= 0.116.3)
54
+ dependabot-docker (0.116.3)
55
+ dependabot-common (= 0.116.3)
56
+ dependabot-elm (0.116.3)
57
+ dependabot-common (= 0.116.3)
58
+ dependabot-git_submodules (0.116.3)
59
+ dependabot-common (= 0.116.3)
60
+ dependabot-github_actions (0.116.3)
61
+ dependabot-common (= 0.116.3)
62
+ dependabot-go_modules (0.116.3)
63
+ dependabot-common (= 0.116.3)
64
+ dependabot-gradle (0.116.3)
65
+ dependabot-common (= 0.116.3)
66
+ dependabot-hex (0.116.3)
67
+ dependabot-common (= 0.116.3)
68
+ dependabot-maven (0.116.3)
69
+ dependabot-common (= 0.116.3)
70
+ dependabot-npm_and_yarn (0.116.3)
71
+ dependabot-common (= 0.116.3)
72
+ dependabot-nuget (0.116.3)
73
+ dependabot-common (= 0.116.3)
74
+ dependabot-omnibus (0.116.3)
75
+ dependabot-bundler (= 0.116.3)
76
+ dependabot-cargo (= 0.116.3)
77
+ dependabot-common (= 0.116.3)
78
+ dependabot-composer (= 0.116.3)
79
+ dependabot-dep (= 0.116.3)
80
+ dependabot-docker (= 0.116.3)
81
+ dependabot-elm (= 0.116.3)
82
+ dependabot-git_submodules (= 0.116.3)
83
+ dependabot-github_actions (= 0.116.3)
84
+ dependabot-go_modules (= 0.116.3)
85
+ dependabot-gradle (= 0.116.3)
86
+ dependabot-hex (= 0.116.3)
87
+ dependabot-maven (= 0.116.3)
88
+ dependabot-npm_and_yarn (= 0.116.3)
89
+ dependabot-nuget (= 0.116.3)
90
+ dependabot-python (= 0.116.3)
91
+ dependabot-terraform (= 0.116.3)
92
+ dependabot-python (0.116.3)
93
+ dependabot-common (= 0.116.3)
94
+ dependabot-terraform (0.116.3)
95
+ dependabot-common (= 0.116.3)
96
+ docker_registry2 (1.9.0)
97
+ rest-client (>= 1.8.0)
98
+ domain_name (0.5.20190701)
99
+ unf (>= 0.0.5, < 1.0.0)
100
+ excon (0.71.1)
101
+ faraday (1.0.0)
102
+ multipart-post (>= 1.2, < 3)
103
+ gitlab (4.13.1)
104
+ httparty (~> 0.14, >= 0.14.0)
105
+ terminal-table (~> 1.5, >= 1.5.1)
106
+ http-accept (1.7.0)
107
+ http-cookie (1.0.3)
108
+ domain_name (~> 0.5)
109
+ httparty (0.17.3)
110
+ mime-types (~> 3.0)
111
+ multi_xml (>= 0.5.2)
112
+ i18n (1.8.2)
113
+ concurrent-ruby (~> 1.0)
114
+ jmespath (1.4.0)
115
+ mime-types (3.3.1)
116
+ mime-types-data (~> 3.2015)
117
+ mime-types-data (3.2019.1009)
118
+ mini_portile2 (2.4.0)
119
+ minitest (5.14.0)
120
+ multi_xml (0.6.0)
121
+ multipart-post (2.1.1)
122
+ netrc (0.11.0)
123
+ nokogiri (1.10.7)
124
+ mini_portile2 (~> 2.4.0)
125
+ octokit (4.15.0)
126
+ faraday (>= 0.9)
127
+ sawyer (~> 0.8.0, >= 0.5.3)
128
+ pandoc-ruby (2.0.2)
129
+ parseconfig (1.0.8)
130
+ parser (2.7.0.2)
131
+ ast (~> 2.4.0)
132
+ public_suffix (4.0.3)
133
+ rake (12.3.3)
134
+ rest-client (2.1.0)
135
+ http-accept (>= 1.7.0, < 2.0)
136
+ http-cookie (>= 1.0.2, < 2.0)
137
+ mime-types (>= 1.16, < 4.0)
138
+ netrc (~> 0.8)
139
+ ruby-enum (0.7.2)
140
+ i18n
141
+ sawyer (0.8.2)
142
+ addressable (>= 2.3.5)
143
+ faraday (> 0.8, < 2.0)
144
+ terminal-table (1.8.0)
145
+ unicode-display_width (~> 1.1, >= 1.1.1)
146
+ toml-rb (2.0.1)
147
+ citrus (~> 3.0, > 3.0)
148
+ unf (0.1.4)
149
+ unf_ext
150
+ unf_ext (0.0.7.6)
151
+ unicode-display_width (1.6.1)
152
+
153
+ PLATFORMS
154
+ ruby
155
+
156
+ DEPENDENCIES
157
+ dependabot-gitea!
158
+ minitest (~> 5.0)
159
+ rake (~> 12.0)
160
+
161
+ BUNDLED WITH
162
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 dany1468
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Dependabot::Gitea
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dependabot/gitea`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dependabot-gitea'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dependabot-gitea
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dependabot-gitea.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dependabot/gitea"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/dependabot/gitea/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'dependabot-gitea'
5
+ spec.version = Dependabot::Gitea::VERSION
6
+ spec.authors = ['dany1468']
7
+ spec.email = ['dany1468@gmail.com']
8
+
9
+ spec.summary = %q{dependabot Gitea plugin}
10
+ spec.description = %q{dependabot Gitea plugin}
11
+ spec.homepage = 'https://github.com/dany1468/dependabot-gitea'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://github.com/dany1468/dependabot-gitea'
17
+ spec.metadata['changelog_uri'] = 'https://github.com/dany1468/dependabot-gitea'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_runtime_dependency 'dependabot-omnibus'
29
+ end
@@ -0,0 +1,12 @@
1
+ require 'dependabot/gitea/version'
2
+ require 'hack/dependabot-core/common/lib/dependabot/clients/gitea'
3
+ require 'hack/dependabot-core/common/lib/dependabot/fire_fetchers/base'
4
+ require 'hack/dependabot-core/common/lib/dependabot/pull_request_creator'
5
+ require 'hack/dependabot-core/common/lib/dependabot/source'
6
+
7
+ module Dependabot
8
+ module Gitea
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Dependabot
2
+ module Gitea
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dependabot/shared_helpers"
4
+ require "excon"
5
+ require 'ostruct'
6
+
7
+ module Dependabot
8
+ module Clients
9
+ class Gitea
10
+ class NotFound < StandardError; end
11
+
12
+ #######################
13
+ # Constructor methods #
14
+ #######################
15
+
16
+ def self.for_source(source:, credentials:)
17
+ credential =
18
+ credentials.
19
+ select { |cred| cred["type"] == "git_source" }.
20
+ find { |cred| cred["host"] == source.hostname }
21
+
22
+ new(source, credential)
23
+ end
24
+
25
+ ##########
26
+ # Client #
27
+ ##########
28
+
29
+ def initialize(source, credentials)
30
+ @source = source
31
+ @credentials = credentials
32
+ end
33
+
34
+ def fetch_commit(_repo, branch)
35
+ response = get(source.api_endpoint + "repos/" +
36
+ "#{source.repo}/" + "branches/" + branch)
37
+
38
+ JSON.parse(response.body).fetch("commit").fetch("id")
39
+ end
40
+
41
+ def labels(_repo)
42
+ response = get(source.api_endpoint + "repos/" +
43
+ "#{source.repo}/" + "labels")
44
+
45
+ JSON.parse(response.body, object_class: OpenStruct)
46
+ end
47
+
48
+ def fetch_default_branch(_repo)
49
+ response = get(source.api_endpoint + "repos/" +
50
+ source.repo)
51
+
52
+ JSON.parse(response.body).fetch("default_branch")
53
+ end
54
+
55
+ def fetch_repo_contents(commit = nil, path = nil)
56
+ response = get(source.api_endpoint + "repos/" +
57
+ "#{source.repo}/" + "contents/" + path, {ref: commit})
58
+
59
+ JSON.parse(response.body)
60
+ end
61
+
62
+ def fetch_repo_contents_treeroot(commit = nil, path = nil)
63
+ raise # not-implemented
64
+ end
65
+
66
+ def fetch_file_contents(commit, path)
67
+ fetch_repo_contents(commit, path)
68
+ end
69
+
70
+ def commits(branch_name = nil)
71
+ response = get(source.api_endpoint + "repos/" +
72
+ "#{source.repo}/" + "commits")
73
+
74
+ JSON.parse(response.body, object_class: OpenStruct)
75
+ end
76
+
77
+ def branch(branch_name)
78
+ raise
79
+ end
80
+
81
+ def pull_requests(source_branch, target_branch)
82
+ raise
83
+ end
84
+
85
+ def create_commit(branch_name, base_commit, commit_message, files,
86
+ author_details)
87
+ head_file = files.first
88
+ tail_files = files.drop(1)
89
+
90
+ res = fetch_repo_contents(base_commit, head_file.path)
91
+
92
+ content = {
93
+ new_branch: branch_name,
94
+ content: Base64.encode64(head_file.content),
95
+ message: commit_message,
96
+ sha: res.fetch('sha'),
97
+ branch: 'master'
98
+ }
99
+
100
+ response = put(source.api_endpoint + "repos/" +
101
+ "#{source.repo}/" + "contents" + head_file.path, content.to_json)
102
+ end
103
+
104
+ def create_pull_request(pr_name, source_branch, target_branch,
105
+ pr_description, labels)
106
+ content = {
107
+ base: target_branch,
108
+ head: source_branch,
109
+ title: pr_name,
110
+ body: pr_description,
111
+ }
112
+
113
+ response = post(source.api_endpoint + "repos/" +
114
+ "#{source.repo}/" + "pulls", content.to_json)
115
+ end
116
+
117
+ def get(url, extra_query = {})
118
+ response = Excon.get(
119
+ url,
120
+ query: {access_token: credentials&.fetch("password")}.merge(extra_query),
121
+ idempotent: true,
122
+ **SharedHelpers.excon_defaults
123
+ )
124
+ raise NotFound if response.status == 404
125
+
126
+ response
127
+ end
128
+
129
+ def post(url, json)
130
+ response = Excon.post(
131
+ url,
132
+ headers: {
133
+ "Content-Type" => "application/json"
134
+ },
135
+ body: json,
136
+ query: {access_token: credentials&.fetch("password")},
137
+ idempotent: true,
138
+ **SharedHelpers.excon_defaults
139
+ )
140
+ raise NotFound if response.status == 404
141
+
142
+ response
143
+ end
144
+
145
+ def put(url, json)
146
+ response = Excon.put(
147
+ url,
148
+ headers: {
149
+ "Content-Type" => "application/json"
150
+ },
151
+ body: json,
152
+ query: {access_token: credentials&.fetch("password")},
153
+ idempotent: true,
154
+ **SharedHelpers.excon_defaults
155
+ )
156
+ raise NotFound if response.status == 404
157
+
158
+ response
159
+ end
160
+
161
+ private
162
+
163
+ attr_reader :credentials
164
+ attr_reader :source
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hack/dependabot-core/common/lib/dependabot/clients/gitea"
4
+
5
+ module Dependabot
6
+ module FileFetchers
7
+ class Base
8
+
9
+ # override
10
+ def _fetch_repo_contents_fully_specified(provider, repo, path, commit)
11
+ case provider
12
+ when "github"
13
+ _github_repo_contents(repo, path, commit)
14
+ when "gitlab"
15
+ _gitlab_repo_contents(repo, path, commit)
16
+ when "azure"
17
+ _azure_repo_contents(path, commit)
18
+ when "bitbucket"
19
+ _bitbucket_repo_contents(repo, path, commit)
20
+ when "gitea"
21
+ _gitea_repo_contents(repo, path, commit)
22
+ when "codecommit"
23
+ _codecommit_repo_contents(repo, path, commit)
24
+ else raise "Unsupported provider '#{provider}'."
25
+ end
26
+ end
27
+
28
+ def _gitea_repo_contents(repo, path, commit)
29
+ response = gitea_client.fetch_repo_contents(commit, path)
30
+
31
+ response.map do |file|
32
+ OpenStruct.new(
33
+ name: file.fetch('name'),
34
+ path: file.fetch('path'),
35
+ type: file.fetch('type'),
36
+ size: file.fetch('size')
37
+ )
38
+ end
39
+ end
40
+
41
+ # override
42
+ def _fetch_file_content_fully_specified(provider, repo, path, commit)
43
+ case provider
44
+ when "github"
45
+ _fetch_file_content_from_github(path, repo, commit)
46
+ when "gitlab"
47
+ tmp = gitlab_client.get_file(repo, path, commit).content
48
+ Base64.decode64(tmp).force_encoding("UTF-8").encode
49
+ when "azure"
50
+ azure_client.fetch_file_contents(commit, path)
51
+ when "gitea"
52
+ tmp = gitea_client.fetch_repo_contents(commit, path)
53
+ Base64.decode64(tmp.fetch('content')).force_encoding("UTF-8").encode
54
+ when "bitbucket"
55
+ bitbucket_client.fetch_file_contents(repo, commit, path)
56
+ when "codecommit"
57
+ codecommit_client.fetch_file_contents(repo, commit, path)
58
+ else raise "Unsupported provider '#{source.provider}'."
59
+ end
60
+ end
61
+
62
+ # override
63
+ def client_for_provider
64
+ case source.provider
65
+ when "github" then github_client
66
+ when "gitlab" then gitlab_client
67
+ when "azure" then azure_client
68
+ when "gitea" then gitea_client
69
+ when "bitbucket" then bitbucket_client
70
+ when "codecommit" then codecommit_client
71
+ else raise "Unsupported provider '#{source.provider}'."
72
+ end
73
+ end
74
+
75
+ def gitea_client
76
+ @gitea_client ||=
77
+ Dependabot::Clients::Gitea.for_source(source: source, credentials: credentials)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dependabot/metadata_finders"
4
+
5
+ module Dependabot
6
+ class PullRequestCreator
7
+ require "hack/dependabot-core/common/lib/dependabot/clients/gitea"
8
+ require "hack/dependabot-core/common/lib/dependabot/pull_request_creator/labeler"
9
+ require "hack/dependabot-core/common/lib/dependabot/pull_request_creator/gitea"
10
+ require "hack/dependabot-core/common/lib/dependabot/pull_request_creator/pr_name_prefixer"
11
+
12
+ # override
13
+ def create
14
+ case source.provider
15
+ when "github" then github_creator.create
16
+ when "gitlab" then gitlab_creator.create
17
+ when "azure" then azure_creator.create
18
+ when "gitea" then gitea_creator.create
19
+ when "codecommit" then codecommit_creator.create
20
+ else raise "Unsupported provider #{source.provider}"
21
+ end
22
+ end
23
+
24
+ def gitea_creator
25
+ Gitea.new(
26
+ source: source,
27
+ branch_name: branch_namer.new_branch_name,
28
+ base_commit: base_commit,
29
+ credentials: credentials,
30
+ files: files,
31
+ commit_message: message_builder.commit_message,
32
+ pr_description: message_builder.pr_message,
33
+ pr_name: message_builder.pr_name,
34
+ author_details: author_details,
35
+ labeler: labeler
36
+ )
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hack/dependabot-core/common/lib/dependabot/clients/gitea"
4
+ require "dependabot/pull_request_creator"
5
+
6
+ module Dependabot
7
+ class PullRequestCreator
8
+ class Gitea
9
+ attr_reader :source, :branch_name, :base_commit, :credentials,
10
+ :files, :commit_message, :pr_description, :pr_name,
11
+ :author_details, :labeler
12
+
13
+ def initialize(source:, branch_name:, base_commit:, credentials:,
14
+ files:, commit_message:, pr_description:, pr_name:,
15
+ author_details:, labeler:)
16
+ @source = source
17
+ @branch_name = branch_name
18
+ @base_commit = base_commit
19
+ @credentials = credentials
20
+ @files = files
21
+ @commit_message = commit_message
22
+ @pr_description = pr_description
23
+ @pr_name = pr_name
24
+ @author_details = author_details
25
+ @labeler = labeler
26
+ end
27
+
28
+ def create
29
+ return if branch_exists? && pull_request_exists?
30
+
31
+ # For Azure we create or update a branch in the same request as creating
32
+ # a commit (so we don't need create or update branch logic here)
33
+ create_commit
34
+
35
+ create_pull_request
36
+ end
37
+
38
+ private
39
+
40
+ def gitea_client_for_source
41
+ @gitea_client_for_source ||=
42
+ Dependabot::Clients::Gitea.for_source(
43
+ source: source,
44
+ credentials: credentials
45
+ )
46
+ end
47
+
48
+ def branch_exists?
49
+ @branch_ref ||= gitea_client_for_source.branch(branch_name)
50
+
51
+ @branch_ref
52
+ rescue
53
+ false
54
+ end
55
+
56
+ def pull_request_exists?
57
+ gitea_client_for_source.pull_requests(
58
+ branch_name,
59
+ source.branch || default_branch
60
+ ).any?
61
+ end
62
+
63
+ def create_commit
64
+ author = author_details&.slice(:name, :email, :date)
65
+ author = nil unless author&.any?
66
+
67
+ gitea_client_for_source.create_commit(
68
+ branch_name,
69
+ base_commit,
70
+ commit_message,
71
+ files,
72
+ author
73
+ )
74
+ end
75
+
76
+ def create_pull_request
77
+ gitea_client_for_source.create_pull_request(
78
+ pr_name,
79
+ branch_name,
80
+ source.branch || default_branch,
81
+ pr_description,
82
+ labeler.labels_for_pr
83
+ )
84
+ end
85
+
86
+ def default_branch
87
+ @default_branch ||=
88
+ gitea_client_for_source.fetch_default_branch(source.repo)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hack/dependabot-core/common/lib/dependabot/clients/gitea"
4
+
5
+ module Dependabot
6
+ class PullRequestCreator
7
+ class Labeler
8
+ # override
9
+ def labels
10
+ @labels ||=
11
+ case source.provider
12
+ when "github" then fetch_github_labels
13
+ when "gitlab" then fetch_gitlab_labels
14
+ when "azure" then fetch_azure_labels
15
+ when "gitea" then fetch_gitea_labels
16
+ else raise "Unsupported provider #{source.provider}"
17
+ end
18
+ end
19
+
20
+ def fetch_gitea_labels
21
+ gitea_client_for_source.
22
+ labels(source.repo).
23
+ map(&:name)
24
+ end
25
+
26
+ def gitea_client_for_source
27
+ @gitea_client_for_source ||=
28
+ Dependabot::Clients::Gitea.for_source(
29
+ source: source,
30
+ credentials: credentials
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hack/dependabot-core/common/lib/dependabot/clients/gitea"
4
+
5
+ module Dependabot
6
+ class PullRequestCreator
7
+ class PrNamePrefixer
8
+ # override
9
+ def recent_commit_messages
10
+ case source.provider
11
+ when "github" then recent_github_commit_messages
12
+ when "gitlab" then recent_gitlab_commit_messages
13
+ when "azure" then recent_azure_commit_messages
14
+ when "gitea" then recent_gitea_commit_messages
15
+ when "codecommit" then recent_codecommit_commit_messages
16
+ else raise "Unsupported provider: #{source.provider}"
17
+ end
18
+ end
19
+
20
+ def recent_gitea_commit_messages
21
+ recent_gitea_commits.
22
+ reject { |c| c.author&.type == "Bot" }.
23
+ reject { |c| c.commit&.message&.start_with?("Merge") }.
24
+ map(&:commit).
25
+ map(&:message).
26
+ compact.
27
+ map(&:strip)
28
+ end
29
+
30
+ def last_dependabot_commit_message
31
+ @last_dependabot_commit_message ||=
32
+ case source.provider
33
+ when "github" then last_github_dependabot_commit_message
34
+ when "gitlab" then last_gitlab_dependabot_commit_message
35
+ when "azure" then last_azure_dependabot_commit_message
36
+ when "gitea" then last_gitea_dependabot_commit_message
37
+ when "codecommit" then last_codecommit_dependabot_commit_message
38
+ else raise "Unsupported provider: #{source.provider}"
39
+ end
40
+ end
41
+
42
+ def last_gitea_dependabot_commit_message
43
+ recent_gitea_commits.
44
+ reject { |c| c.commit&.message&.start_with?("Merge") }.
45
+ find { |c| c.commit.author&.name&.include?("dependabot") }&.
46
+ commit&.
47
+ message&.
48
+ strip
49
+ end
50
+
51
+ def recent_gitea_commits
52
+ @recent_gitea_commits ||=
53
+ gitea_client_for_source.commits
54
+ end
55
+
56
+ def gitea_client_for_source
57
+ @gitea_client_for_source ||=
58
+ Dependabot::Clients::Gitea.for_source(
59
+ source: source,
60
+ credentials: credentials
61
+ )
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ class Source
5
+ # override
6
+ def url_with_directory
7
+ return url if [nil, ".", "/"].include?(directory)
8
+
9
+ case provider
10
+ when "github", "gitlab"
11
+ when "github", "gitlab", "gitea"
12
+ path = Pathname.new(File.join("tree/#{branch || 'HEAD'}", directory)).
13
+ cleanpath.to_path
14
+ url + "/" + path
15
+ when "bitbucket"
16
+ path = Pathname.new(File.join("src/#{branch || 'default'}", directory)).
17
+ cleanpath.to_path
18
+ url + "/" + path
19
+ when "azure"
20
+ url + "?path=#{directory}"
21
+ when "codecommit"
22
+ raise "The codecommit provider does not utilize URLs"
23
+ else raise "Unexpected repo provider '#{provider}'"
24
+ end
25
+ end
26
+
27
+ # override
28
+ def default_hostname(provider)
29
+ case provider
30
+ when "github" then "github.com"
31
+ when "bitbucket" then "bitbucket.org"
32
+ when "gitlab" then "gitlab.com"
33
+ when "azure" then "dev.azure.com"
34
+ when "gitea" then "localhost:3000"
35
+ when "codecommit" then "us-east-1"
36
+ else raise "Unexpected provider '#{provider}'"
37
+ end
38
+ end
39
+
40
+ # override
41
+ def default_api_endpoint(provider)
42
+ case provider
43
+ when "github" then "https://api.github.com/"
44
+ when "bitbucket" then "https://api.bitbucket.org/2.0/"
45
+ when "gitlab" then "https://gitlab.com/api/v4"
46
+ when "azure" then "https://dev.azure.com/"
47
+ when "gitea" then "http://localhost:3000/api/v1"
48
+ when "codecommit" then nil
49
+ else raise "Unexpected provider '#{provider}'"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,152 @@
1
+ # This script is designed to loop through all dependencies in a GHE, GitLab or
2
+ # Azure DevOps project, creating PRs where necessary.
3
+
4
+ require "dependabot/file_fetchers"
5
+ require "dependabot/file_parsers"
6
+ require "dependabot/update_checkers"
7
+ require "dependabot/file_updaters"
8
+ require "dependabot/pull_request_creator"
9
+ require "dependabot/omnibus"
10
+ require "gitlab"
11
+ require 'dependabot/gitea'
12
+
13
+ credentials = [
14
+ {
15
+ "type" => "git_source",
16
+ "host" => "github.com",
17
+ "username" => "x-access-token",
18
+ "password" => ENV["GITHUB_ACCESS_TOKEN"] # A GitHub access token with read access to public repos
19
+ }
20
+ ]
21
+
22
+ # Full name of the repo you want to create pull requests for.
23
+ repo_name = ENV["PROJECT_PATH"] # namespace/project
24
+
25
+ # Directory where the base dependency files are.
26
+ directory = ENV["DIRECTORY_PATH"] || "/"
27
+
28
+ # Name of the package manager you'd like to do the update for. Options are:
29
+ # - bundler
30
+ # - pip (includes pipenv)
31
+ # - npm_and_yarn
32
+ # - maven
33
+ # - gradle
34
+ # - cargo
35
+ # - hex
36
+ # - composer
37
+ # - nuget
38
+ # - dep
39
+ # - go_modules
40
+ # - elm
41
+ # - submodules
42
+ # - docker
43
+ # - terraform
44
+ package_manager = ENV["PACKAGE_MANAGER"] || "bundler"
45
+
46
+ if ENV["GITEA_ACCESS_TOKEN"]
47
+ gitea_hostname = ENV["GITEA_HOSTNAME"] || "localhost:3000"
48
+
49
+ credentials << {
50
+ "type" => "git_source",
51
+ "host" => gitea_hostname,
52
+ "username" => "x-access-token",
53
+ "password" => ENV["GITEA_ACCESS_TOKEN"]
54
+ }
55
+
56
+ source = Dependabot::Source.new(
57
+ provider: "gitea",
58
+ hostname: gitea_hostname,
59
+ api_endpoint: "http://#{gitea_hostname}/api/v1/",
60
+ repo: repo_name,
61
+ directory: directory,
62
+ branch: nil,
63
+ )
64
+ else
65
+ raise 'require GITEA_ACCESS_TOKEN environment variable'
66
+ end
67
+
68
+ ##############################
69
+ # Fetch the dependency files #
70
+ ##############################
71
+ puts "Fetching #{package_manager} dependency files for #{repo_name}"
72
+ fetcher = Dependabot::FileFetchers.for_package_manager(package_manager).new(
73
+ source: source,
74
+ credentials: credentials,
75
+ )
76
+
77
+ files = fetcher.files
78
+ commit = fetcher.commit
79
+
80
+ puts "Fetched ltgt #{fetcher.commit} #{fetcher.files.map(&:path)}"
81
+
82
+ ##############################
83
+ # Parse the dependency files #
84
+ ##############################
85
+ puts "Parsing dependencies information"
86
+ parser = Dependabot::FileParsers.for_package_manager(package_manager).new(
87
+ dependency_files: files,
88
+ source: source,
89
+ credentials: credentials,
90
+ )
91
+
92
+ dependencies = parser.parse
93
+
94
+ dependencies.select(&:top_level?).each do |dep|
95
+ #########################################
96
+ # Get update details for the dependency #
97
+ #########################################
98
+ checker = Dependabot::UpdateCheckers.for_package_manager(package_manager).new(
99
+ dependency: dep,
100
+ dependency_files: files,
101
+ credentials: credentials,
102
+ )
103
+
104
+ next if checker.up_to_date?
105
+
106
+ requirements_to_unlock =
107
+ if !checker.requirements_unlocked_or_can_be?
108
+ if checker.can_update?(requirements_to_unlock: :none) then :none
109
+ else :update_not_possible
110
+ end
111
+ elsif checker.can_update?(requirements_to_unlock: :own) then :own
112
+ elsif checker.can_update?(requirements_to_unlock: :all) then :all
113
+ else :update_not_possible
114
+ end
115
+
116
+ next if requirements_to_unlock == :update_not_possible
117
+
118
+ updated_deps = checker.updated_dependencies(
119
+ requirements_to_unlock: requirements_to_unlock
120
+ )
121
+
122
+ #####################################
123
+ # Generate updated dependency files #
124
+ #####################################
125
+ print " - Updating #{dep.name} (from #{dep.version})…"
126
+ updater = Dependabot::FileUpdaters.for_package_manager(package_manager).new(
127
+ dependencies: updated_deps,
128
+ dependency_files: files,
129
+ credentials: credentials,
130
+ )
131
+
132
+ updated_files = updater.updated_dependency_files
133
+
134
+ ########################################
135
+ # Create a pull request for the update #
136
+ ########################################
137
+ pr_creator = Dependabot::PullRequestCreator.new(
138
+ source: source,
139
+ base_commit: commit,
140
+ dependencies: updated_deps,
141
+ files: updated_files,
142
+ credentials: credentials,
143
+ assignees: [(ENV["PULL_REQUESTS_ASSIGNEE"] || ENV["GITLAB_ASSIGNEE_ID"])&.to_i],
144
+ label_language: true,
145
+ )
146
+ pull_request = pr_creator.create
147
+ puts " submitted"
148
+
149
+ next unless pull_request
150
+ end
151
+
152
+ puts "Done"
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dependabot-gitea
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dany1468
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dependabot-omnibus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: dependabot Gitea plugin
28
+ email:
29
+ - dany1468@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - dependabot-gitea.gemspec
43
+ - lib/dependabot/gitea.rb
44
+ - lib/dependabot/gitea/version.rb
45
+ - lib/hack/dependabot-core/common/lib/dependabot/clients/gitea.rb
46
+ - lib/hack/dependabot-core/common/lib/dependabot/fire_fetchers/base.rb
47
+ - lib/hack/dependabot-core/common/lib/dependabot/pull_request_creator.rb
48
+ - lib/hack/dependabot-core/common/lib/dependabot/pull_request_creator/gitea.rb
49
+ - lib/hack/dependabot-core/common/lib/dependabot/pull_request_creator/labeler.rb
50
+ - lib/hack/dependabot-core/common/lib/dependabot/pull_request_creator/pr_name_prefixer.rb
51
+ - lib/hack/dependabot-core/common/lib/dependabot/source.rb
52
+ - scripts/generic-update-script.rb
53
+ homepage: https://github.com/dany1468/dependabot-gitea
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/dany1468/dependabot-gitea
58
+ source_code_uri: https://github.com/dany1468/dependabot-gitea
59
+ changelog_uri: https://github.com/dany1468/dependabot-gitea
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.1.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: dependabot Gitea plugin
79
+ test_files: []