openrewrite / rewrite-build-gradle-plugin

Common build logic for building OpenRewrite and recipe jars.
Apache License 2.0
4 stars 5 forks source link

Include git authorship metadata of recipes as yaml files in resources directory #5

Closed sambsnyd closed 1 year ago

sambsnyd commented 1 year ago

We need to update our build plugin to include a descriptor of recipe authorship in yaml format into its src/main/resources directory. It is difficult for a build plugin to tell which java sources are recipes and which are unrelated java source files. So for simplicity of implementation we can create a descriptor for every java source file.

Git can be queried with this information on the command line with: git shortlog --numbered --summary --email -- <path>

Example output from rewrite-python. The number is the count of commits, sorted descending.

> git shortlog --numbered --summary --email -- src/test/java/org/openrewrite/python/tree/AssignTest.java
     3  Gary Olsen <gary@moderne.io>
     2  Jonathan Schneider <jkschneider@gmail.com>
     1  Sam Snyder <sam@moderne.io>
     1  Tim te Beek <timtebeek@gmail.com>
     1  Yeikel <email@yeikel.com>

It is likely more convenient and efficient to use jgit than to shell out. jgit might already be part of the gradle api.

For each such java file in the main source set, we should produce an entry in src/main/resources/META-INF/rewrite/recipe-authors.yml that looks like:

---
type: specs.openrewrite.org/v1beta/authors
name: org.openrewrite.python.tree.AssignTest
authors:
  - name: Gary Olsen
    email: gary@moderne.io
    commits: 3
  - name: # etc. 
  - name: 

Both RewriteLanguagePlugin and RewriteRecipeLibraryPlugin should register a task which produces this yaml file. The java plugin's ProcessResources task should be configured to copy from it so that it is guaranteed this ends up bundled in the jar.

knutwannheden commented 1 year ago

It would be even nicer if we could additionally also query GitHub so that we can correlate committers with GitHub accounts, since often an individual user uses different combinations of name and email. See the output for the openrewrite/rewrite repository itself:

image
knutwannheden commented 1 year ago

The issue mentioned above can be cleaned up using a .mailmap file. The result then looks something like this:

image

Since JGit currently neither supports .mailmap nor the shortlog command, it probably makes more sense to use the git executable directly in a first step.

sambsnyd commented 1 year ago

While there are enhancements to be made, such as encorporating .mailmap or a similar mechanism to map committer names to github account names, the basic implementation of this is now complete