Skip to content

Commit

Permalink
Merge pull request #213 from KnapsackPro/fix-git-shallow
Browse files Browse the repository at this point in the history
Fix hanging CI when `git fetch --shallow-since` takes too long
  • Loading branch information
ArturT authored Jul 21, 2023
2 parents 313d557 + f284c20 commit 054f0e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### 5.3.3

* Fix hanging CI when `git fetch --shallow-since` takes too long

https://github.com/KnapsackPro/knapsack_pro-ruby/pull/213

https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v5.3.2...v5.3.3

### 5.3.2

* On top of 5.3.1, avoid noise to stderr when git is not available when collecting the build author
Expand Down
1 change: 1 addition & 0 deletions lib/knapsack_pro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'rake/testtask'
require 'digest'
require 'securerandom'
require 'timeout'
require_relative 'knapsack_pro/urls'
require_relative 'knapsack_pro/version'
require_relative 'knapsack_pro/extensions/time'
Expand Down
16 changes: 14 additions & 2 deletions lib/knapsack_pro/repository_adapters/git_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ def build_author
private

def git_commit_authors
if KnapsackPro::Config::Env.ci?
`git fetch --shallow-since "one month ago" --quiet 2>/dev/null`
if KnapsackPro::Config::Env.ci? && shallow_repository?
command = 'git fetch --shallow-since "one month ago" --quiet 2>/dev/null'
begin
Timeout.timeout(5) do
`#{command}`
end
rescue Timeout::Error
KnapsackPro.logger.debug("Skip the `#{command}` command because it took too long.")
end
end

`git log --since "one month ago" 2>/dev/null | git shortlog --summary --email 2>/dev/null`
Expand All @@ -52,6 +59,11 @@ def git_build_author
`git log --format="%aN <%aE>" -1 2>/dev/null`
end

def shallow_repository?
result = `git rev-parse --is-shallow-repository 2>/dev/null`
result.strip == 'true'
end

def working_dir
dir = KnapsackPro::Config::Env.project_dir
File.expand_path(dir)
Expand Down

0 comments on commit 054f0e1

Please sign in to comment.