Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/check-contributors.rb
1677 views
1
#!/usr/bin/env ruby
2
# frozen_string_literal: true
3
4
# Checks the header of a tutorial or slides file fo the current contributor list
5
# Then compares against the people who have touched that file in git using the git log
6
#
7
# Each tutorial or slides file needs to be checked individually.
8
#
9
# If there are unknown contributors, create a .mailmap file like:
10
# <gh-username> <[email protected]>
11
# <gh-username> <[email protected]>
12
#
13
# This is the format of git's mail-map
14
# https://www.git-scm.com/docs/git-check-mailmap
15
# We probably should not commit this file, some people don't want their old emails
16
# listed so publicly.
17
18
require 'yaml'
19
20
if ARGV.size != 1
21
puts 'Please run with ./bin/check-contributors path/to/tutorial.md/or/slides.html'
22
exit
23
end
24
25
fn = ARGV[0]
26
27
# Any error messages
28
# errs = []
29
data = YAML.load_file(fn)
30
current_contributors = data['contributors']
31
32
# Full Contributors Data
33
CONTRIBUTORS = YAML.load_file('CONTRIBUTORS.yaml')
34
contributor_emails = CONTRIBUTORS.map do |k, v|
35
[v['email'], k] if v && v.key?('email')
36
end.compact.to_h
37
38
file_contributors = `git log --use-mailmap --follow --pretty=%aE #{fn}`.lines.sort.uniq
39
40
fixed_contribs = file_contributors.map do |email|
41
email = email.strip
42
if /users.noreply.github.com/.match(email)
43
parts = /^(?<_num>[0-9]+\+)?(?<id>.*)@users.noreply.github.com/.match(email)
44
# we just want their gh id
45
parts[:id]
46
elsif contributor_emails.key?(email)
47
contributor_emails[email]
48
else
49
email
50
end
51
end
52
53
# known contributors
54
known = fixed_contribs.reject { |x| /@/.match(x) }
55
unknown = fixed_contribs.select { |x| /@/.match(x) }
56
57
missing = (known - current_contributors).sort.uniq
58
# These contributors not yet recognised
59
puts "Missing contributors: #{missing}" if missing.length.positive?
60
61
# These emails might map to known users, but we don't know yet.
62
puts "Unknown emails: #{unknown.sort.uniq}" if unknown.length.positive?
63
64