Skip to content

Instantly share code, notes, and snippets.

@ashwanthkumar
Last active January 14, 2019 07:27
Show Gist options
  • Save ashwanthkumar/fed7497ae950d8c1be3379c8c9df91b6 to your computer and use it in GitHub Desktop.
Save ashwanthkumar/fed7497ae950d8c1be3379c8c9df91b6 to your computer and use it in GitHub Desktop.
Get the list of all contributors for all the repos within an organization.

Github Contributions Report

This scala program will help you get a report of all contributors to all your repositories within an organization that the user has access to. The output is written in TSV. To configure the Github credentials to work around the Rate Limits, follow the instructions available on http://github-api.kohsuke.org/.

License

http://www.apache.org/licenses/LICENSE-2.0

resolvers += "Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
libraryDependencies += "org.kohsuke" % "github-api" % "1.95"
import java.io.{File, PrintWriter}
import org.kohsuke.github.{GHRepository, GitHub}
import scala.collection.JavaConversions._
// Needs the following in build.sbt
// resolvers += "Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
// libraryDependencies += "org.kohsuke" % "github-api" % "1.95"
// Run the script with the following
// - first argument as the name of the organization
// - second argument with output file where we should write the output
object GithubContributors extends App {
val org = args(0)
val output = args(1)
lazy val writer = new PrintWriter(new File(output))
val headers = List("URL",
"Private/Public",
"Is Forked",
"Number Of Forks",
"Contributor Profile",
"Contributor Name",
"Contributor Email",
"Number Of Contributions")
def privateOrPublic(repo: GHRepository) =
if (repo.isPrivate) "PRIVATE" else "PUBLIC"
def isForked(repo: GHRepository) = if (repo.isFork) "FORKED" else "NOT-FORKED"
def numberOfForks(repo: GHRepository) = repo.getForks
def nameOf(contributor: GHRepository.Contributor) =
Option(contributor.getName).getOrElse(contributor.getLogin)
val github: GitHub = GitHub.connect()
val allRepos = github.getOrganization(org).getRepositories.values().toList
writer.println(headers.mkString("\t"))
allRepos.foreach { repo =>
println(s"Processing the repo - ${repo.getName} (${repo.getHtmlUrl})")
val allContributors = repo.listContributors().toList
allContributors.foreach { contributor =>
val columns = List(
repo.getHtmlUrl,
privateOrPublic(repo),
isForked(repo),
numberOfForks(repo),
contributor.getHtmlUrl,
nameOf(contributor),
contributor.getEmail,
contributor.getContributions
)
writer.println(columns.mkString("\t"))
println(columns.mkString("\t"))
}
writer.flush()
}
writer.flush()
writer.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment