11# standard library
22import logging
3- import os
43import time
54from datetime import datetime
65
6+ from mkdocs_git_revision_date_localized_plugin .ci import raise_ci_warnings
7+
78# 3rd party
89from babel .dates import format_date , get_timezone
9- from git import Repo , Git , GitCommandError , GitCommandNotFound
10+ from git import Repo , GitCommandError , GitCommandNotFound
1011
1112
1213class Util :
@@ -33,32 +34,8 @@ def __init__(self, path: str = ".", config={}):
3334 raise
3435
3536 # Checks if user is running builds on CI
36- # See https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/issues/10
37- if is_shallow_clone (self .repo ):
38- n_commits = commit_count (self .repo )
39-
40- if os .environ .get ("GITLAB_CI" ) and n_commits < 50 :
41- # Default is GIT_DEPTH of 50 for gitlab
42- logging .warning (
43- """
44- Running on a gitlab runner might lead to wrong git revision dates
45- due to a shallow git fetch depth.
46- Make sure to set GIT_DEPTH to 1000 in your .gitlab-ci.yml file.
47- (see https://docs.gitlab.com/ee/user/project/pipelines/settings.html#git-shallow-clone).
48- """
49- )
50- if os .environ .get ("GITHUB_ACTIONS" ) and n_commits == 1 :
51- # Default is fetch-depth of 1 for github actions
52- logging .warning (
53- """
54- Running on github actions might lead to wrong git revision dates
55- due to a shallow git fetch depth.
56- Try setting fetch-depth to 0 in your github action
57- (see https://github.com/actions/checkout).
58- """
59- )
60-
61- # TODO add bitbucket
37+ # and raise appropriate warnings
38+ raise_ci_warnings (self .repo )
6239
6340 @staticmethod
6441 def _date_formats (
@@ -158,38 +135,3 @@ def get_revision_date_for_file(
158135 return self ._date_formats (
159136 unix_timestamp = unix_timestamp , time_zone = time_zone , locale = locale
160137 )
161-
162-
163- def is_shallow_clone (repo : Git ) -> bool :
164- """
165- Helper function to determine if repository
166- is a shallow clone.
167-
168- References:
169- https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/issues/10
170- https://stackoverflow.com/a/37203240/5525118
171-
172- Args:
173- repo (git.Repo): Repository
174-
175- Returns:
176- bool: If a repo is shallow clone
177- """
178- return os .path .exists (".git/shallow" )
179-
180-
181- def commit_count (repo : Git ) -> bool :
182- """
183- Helper function to determine the number of commits in a repository
184-
185- Args:
186- repo (git.Repo): Repository
187-
188- Returns:
189- count (int): Number of commits
190- """
191- refs = repo .for_each_ref ().split ("\n " )
192- refs = [x .split ()[0 ] for x in refs ]
193-
194- counts = [int (repo .rev_list (x , count = True , first_parent = True )) for x in refs ]
195- return max (counts )
0 commit comments