Method: Gitlab::Golang#validate_pseudo_version

Defined in:
lib/gitlab/golang.rb

#validate_pseudo_version(project, version, commit = nil) ⇒ Object

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/gitlab/golang.rb', line 66

def validate_pseudo_version(project, version, commit = nil)
  commit ||= project.repository.commit_by(oid: version.commit_id)

  # Error messages are based on the responses of proxy.golang.org

  # Verify that the SHA fragment references a commit
  raise ArgumentError, 'invalid pseudo-version: unknown commit' unless commit

  # Require the SHA fragment to be 12 characters long
  raise ArgumentError, 'invalid pseudo-version: revision is shorter than canonical' unless version.commit_id.length == 12

  # Require the timestamp to match that of the commit
  raise ArgumentError, 'invalid pseudo-version: does not match version-control timestamp' unless commit.committed_date.strftime('%Y%m%d%H%M%S') == version.timestamp

  commit
end