Path: blob/main/bin/check-contributors.rb
1677 views
#!/usr/bin/env ruby1# frozen_string_literal: true23# Checks the header of a tutorial or slides file fo the current contributor list4# Then compares against the people who have touched that file in git using the git log5#6# Each tutorial or slides file needs to be checked individually.7#8# If there are unknown contributors, create a .mailmap file like:9# <gh-username> <[email protected]>10# <gh-username> <[email protected]>11#12# This is the format of git's mail-map13# https://www.git-scm.com/docs/git-check-mailmap14# We probably should not commit this file, some people don't want their old emails15# listed so publicly.1617require 'yaml'1819if ARGV.size != 120puts 'Please run with ./bin/check-contributors path/to/tutorial.md/or/slides.html'21exit22end2324fn = ARGV[0]2526# Any error messages27# errs = []28data = YAML.load_file(fn)29current_contributors = data['contributors']3031# Full Contributors Data32CONTRIBUTORS = YAML.load_file('CONTRIBUTORS.yaml')33contributor_emails = CONTRIBUTORS.map do |k, v|34[v['email'], k] if v && v.key?('email')35end.compact.to_h3637file_contributors = `git log --use-mailmap --follow --pretty=%aE #{fn}`.lines.sort.uniq3839fixed_contribs = file_contributors.map do |email|40email = email.strip41if /users.noreply.github.com/.match(email)42parts = /^(?<_num>[0-9]+\+)?(?<id>.*)@users.noreply.github.com/.match(email)43# we just want their gh id44parts[:id]45elsif contributor_emails.key?(email)46contributor_emails[email]47else4849end50end5152# known contributors53known = fixed_contribs.reject { |x| /@/.match(x) }54unknown = fixed_contribs.select { |x| /@/.match(x) }5556missing = (known - current_contributors).sort.uniq57# These contributors not yet recognised58puts "Missing contributors: #{missing}" if missing.length.positive?5960# These emails might map to known users, but we don't know yet.61puts "Unknown emails: #{unknown.sort.uniq}" if unknown.length.positive?626364