Git Revision Missing

A simple Java API to list missing commits between 2 versions

License

License

Categories

Categories

Git Development Tools Version Controls
GroupId

GroupId

io.github.gaol
ArtifactId

ArtifactId

git-rev-missing
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Git Revision Missing
A simple Java API to list missing commits between 2 versions
Source Code Management

Source Code Management

https://github.com/gaol/git-rev-missing

Download git-rev-missing

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.gaol/git-rev-missing/ -->
<dependency>
    <groupId>io.github.gaol</groupId>
    <artifactId>git-rev-missing</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.gaol/git-rev-missing/
implementation 'io.github.gaol:git-rev-missing:0.0.2'
// https://jarcasting.com/artifacts/io.github.gaol/git-rev-missing/
implementation ("io.github.gaol:git-rev-missing:0.0.2")
'io.github.gaol:git-rev-missing:jar:0.0.2'
<dependency org="io.github.gaol" name="git-rev-missing" rev="0.0.2">
  <artifact name="git-rev-missing" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.gaol', module='git-rev-missing', version='0.0.2')
)
libraryDependencies += "io.github.gaol" % "git-rev-missing" % "0.0.2"
[io.github.gaol/git-rev-missing "0.0.2"]

Dependencies

compile (8)

Group / Artifact Type Version
org.jboss.set » jboss-aphrodite-github jar 0.7.13.Final
org.jboss.set » jboss-aphrodite-gitlab jar 0.7.13.Final
com.fasterxml.jackson.core : jackson-annotations jar 2.10.2
info.picocli : picocli jar 4.6.1
commons-logging : commons-logging jar 1.2
org.apache.commons : commons-text jar 1.8
org.apache.logging.log4j : log4j-core jar 2.8.2
org.apache.logging.log4j : log4j-jcl jar 2.8.2

test (1)

Group / Artifact Type Version
org.testng : testng jar 6.8.7

Project Modules

There are no modules declared in this project.

git-rev-missing

A simple library/tool to list missing commits when upgrading from one version to another.

This provides a capability to find potential regressions.

How it works

Inside of the tool, it uses Aphrodite to talk with git services like github.com or other gitlab based sites.

It lists commits from one tag/branch from some time ago(name commitsA), then lists commits from the other tag/branch since the same time ago(name commitsB), for each commit(name commit) in commitsA, it tries to search in commitsB following the below steps:

  • If SHA1 of the commit is found in commitsB, the commit is good.
  • If SHA1 of the commit is NOT found in commitsB, it tries to find the commits in commitsB with the same message.
  • For each commit found with same message, tries to compare the diffs between the 2 commits, if the diff is the same, the commit is good(like the ones using rebase or cherry-pick), otherwise, it is missing or suspicious depends on how different they are.
  • For each commit found with similar message(check the message difference ratio, > 0.7 by default), tries to compare the diffs between the 2 commits, if the diff is the same, the commit is considered good, otherwise, it is missing or suspicious depends on how different they are.

NOTE It does not support gerrit/gitweb, it supports github.com and gitlab sites.

How to use it

There are 2 ways to use it

Use it as a Java library

To use this project, add the following dependency to the dependencies section of your build descriptor:

  • Maven (in your pom.xml):
<dependency>
  <groupId>io.github.gaol</groupId>
  <artifactId>git-rev-missing</artifactId>
  <version>${maven.version}</version>
</dependency>
  • Gradle (in your build.gradle file):
compile 'io.github.gaol:git-rev-missing:${maven.version}'

Then take the following example on how to call the API.

public class TestApp {
    public static void main(String[] args) throws Exception {
      GitRevMissing gitRevMissing = GitRevMissing.create(new URL("https://github.com"), username, access_token);
      MissingCommit missCommit = gitRevMissing.missingCommits("ihomeland", "prtest", "revA", "revB");
      if (missCommit.isClean()) {
          logger.info("Great, no missing commits found");
      } else {
            if (missCommit.getCommits() != null && missCommit.getCommits().size() > 0) {
                logger.warn(missCommit.getCommits().size() + " commits were missing in " + revB + "\n");
            }
            if (missCommit.getSuspiciousCommits() != null && missCommit.getSuspiciousCommits().size() > 0) {
                logger.warn(missCommit.getSuspiciousCommits().size() + " commits were suspicious in " + revB + "\n");
            }
            logger.warn(missCommit.toString() + "\n");
      }
      gitRevMissing.release();
    }
}

Use git_rev_missing.sh script

There is a script git_rev_missing.sh can be used to run directly like the following example:

git clone https://github.com/gaol/git-rev-missing
cd git-rev-missing
./git_rev_missing.sh -u my-username -p https://github.com/ihomeland/prtest/compare/revA...revB

The above example tries to find commits in revA, but missing in revB of https://github.com/ihomeland/prtest.

You will see the following similar output:

Apr 10, 2021 8:23:59 PM git_rev_missing.impl missingCommits
INFO: 3 commits are found in revision: revA since: 2020-04-10T06:23:57.623Z
Apr 10, 2021 8:23:59 PM git_rev_missing.impl missingCommits
INFO: 3 commits are found in revision: revB since: 2020-04-10T06:23:57.623Z
Apr 10, 2021 8:23:59 PM git_rev_missing.main call
WARNING: 
  1 commits were missing in revB

Apr 10, 2021 8:23:59 PM git_rev_missing.main call
WARNING: {
  "commits" : [ {
    "commit" : {
      "sha" : "6a7d8dd7fae154653d04b5c0ca6184b3bd40c107",
      "message" : "Update 2nd in a separate file"
    },
    "commitLink" : "https://github.com/ihomeland/prtest/commit/6a7d8dd7fae154653d04b5c0ca6184b3bd40c107"
  } ],
  "clean" : false
}

Config File

Please refer to config.json.example for the configuration format:

{
  "repositoryConfigs": [
    {
      "url": "https://github.com/",
      "username": "my-user-name",
      "password": "my-access-token",
      "type": "GITHUB"
    },
    {
      "url": "https://gitlab.xxx.yyy.com/",
      "username": "my-user-name",
      "password": "my-access-token",
      "type": "GITLAB"
    }
  ]
}

You can put your configuration file(default name is: config.json) in the current directory or home directory. The configuration format is the same as what Aphrodite has.

Please run

./git_rev_missing.sh -h

for more information

Versions

Version
0.0.2
0.0.1