SlideShare una empresa de Scribd logo
1 de 34
Luca Milanesio
GerritForge
Luca@gerritforge.com
http://www.gerritforge.com
Twitter: @gitenterprise
How to script a Plugin
2
About Luca
• Luca Milanesio
Co-founder of GerritForge
• over 20 years of experience
in Agile Development
SCM, CI and ALM worldwide
• Contributor to Jenkins
since 2007 (and previously Hudson)
• Git SCM mentor
for the Enterprise since 2009
• Contributor to Gerrit Code Review community since 2011
3
About GerritForge
Founded in 2009 in London UK
Mission: Agile Enterprise
Products:
4
Agenda
 Where we come from ?
 2 years ago: Gerrit plugins
 We want more plugins
 Create a plugin in 60 seconds
 What, how and when are coming?
 Plugins showcase
5
WHO REMEMBERS
THIS ?
GitTogether 2011
Gerrit 2.2.x
6
Why don’t we
introduce plugins ?
They have been so
successful with
Jenkins
7
Gerrit Hackathon
7th of May 2012
The first “helloworld”
plugin was born
8
WHO REMEMBERS THIS ?
Gerrit Summit 2012
Ver. 2.5.x
9
Gerrit Plugins
Growth
in 2 years
50
10
Can we do more ?
Let's ask Jenkins 
11
PLUGINS SUCCESS
=
COMMUNITY
ENGAGEMENT
12
COMMUNITY
=
BRIDGING
DIFFERENCES
13
That would be very useful for
Gerrit Administrators to be
able to write quick automation
scripts for their daily tasks. I
would prioritize groovy plugin
more for the popularity of
groovy scripting.
I think adding a "scripting
language plugin" to support
plugins written in scripting
languages is a very good idea
Hi all,
I was thinking about extending
Gerrit capabilities to load
plugins / extensions by
providing "wrapper" for other
JVM languages.
So … we asked the Community
I would prefer scala, because
I've already written my plugins
with it. imho the builld process is
the main impediment.
14
CHALLENGE
for building a
Gerrit Plugin
15
NO STEPS, NO BUILD … just do it !
$ cat - > ~/gerrit/plugins/hello-1.0.groovy
import com.google.gerrit.sshd.*
import com.google.gerrit.extensions.annotations.*
@Export("groovy")
class GroovyCommand extends SshCommand {
public void run() { stdout.println "Hi from Groovy" }
}
^D
This sample has 190 chars: you need to type
at least 3.2 chars/sec to complete the sample
in only one minute 
https://gist.github.com/lucamilanesio/9687053
16
IS THAT TRUE ? Let’s check on Gerrit
$ ssh –p 29418 user@localhost gerrit plugin ls
Name Version Status File
----------------------------------------------------------------------
hello 1.0 ENABLED hello-1.0.groovy
Gerrit auto-detects the new Groovy file under
$GERRIT_SITE/plugins, invoke the interpreter
and auto-wrap the class into a self-contained Gerrit
plugin.
Groovy class is compiled into byte-code BUT is
slower than native Java plugin.
17
DOES IT REALLY WORK ?
$ ssh –p 29418 user@localhost hello groovy
Hi from Groovy
No magic … IT IS ALL REAL !
Plugin name (hello) comes from the
script filename.
A new SSH command (groovy) has
been defined in Gerrit associated to
the Groovy script loaded.
18
What about Scala ? Just do it again !
$ cat - > ~/gerrit/plugins/hi-1.0.scala
import com.google.gerrit.sshd._
import com.google.gerrit.extensions.annotations._
@Export("scala")
class ScalaCommand extends SshCommand {
override def run = stdout println "Hi from Scala"
}
^D
Scala is more concise with just 178 chars :
you can take it easy with 2.9 chars/sec to type
it a minute 
https://gist.github.com/lucamilanesio/9687092
19
You have now two plugins loaded
$ ssh –p 29418 user@localhost gerrit plugin ls
Name Version Status File
----------------------------------------------------------------------
hello 1.0 ENABLED hello-1.0.groovy
hi 1.0 ENABLED hi-1.0.scala
There are no differences for Gerrit between
Java, Groovy or Scala plugins: they have the same
dignity and power.
Scala compiler takes longer but byte-code runs at
the same speed as a native Java plugin!
20
Reactions from the Gerrit mailing list …
So i checked it out and tried it, and
what should i say ...
Wow, it rocks! ;-)
Combined with new and shiny
Plugin API the code is really short.
So i started new repo
on gh [1] and created two working
plugins [2], [3], and sure would add
more, so to say,
cookbook-groovy-plugin:
$>ssh gerrit review approve
I59302cbb
$>Approve change: I59302cbb.
What do
YOU think
? 
21
WHAT can scripting plugins do now ?
1. Define new SSH commands
2. Define new REST APIs
3. Listen to Gerrit events
22
HOW can I get Gerrit with scripting plugins ?
Download the Gerrit master with scripting extensions from:
http://ci.gerritforge.com/job/Gerrit-master-scripting/lastSuccessfulBuild/artifact/buck-
out/gen/gerrit-scripting.war
Run Gerrit init and say Y for installing the Scala and Groovy scripting plugins
providers:
*** Plugins
***
Install plugin groovy-provider version v2.9-rc1-325-g96d0d43 [y/N]? Y
Install plugin scala-provider version v2.9-rc1-325-g96d0d43 [y/N]? y
You may want to increase the JVM PermGen on gerrit.config when
loading/unloading scripting plugins
[container]
javaOptions = -XX:MaxPermSize=1024m
23
Scripting plugins
showcase
24
Create a branch through Gerrit API
$ cat - > ~/gerrit/plugins/branch-1.0.groovy
import com.google.gerrit.sshd.*
import com.google.gerrit.extensions.annotations.*
import com.google.gerrit.extensions.api.*
import com.google.gerrit.extensions.api.projects.*
import com.google.inject.*
import org.kohsuke.args4j.*
@Export("create")
@CommandMetaData(name = "create-branch", description = "Create branch")
class CreateBranch extends SshCommand {
@Inject GerritApi api
@Argument(index = 0, usage = "Project name", metaVar = "PROJECT")
String projectName
@Argument(index = 1, usage = "Branch name", metaVar = "BRANCH")
String branchName
@Argument(index = 2, usage = "Branch point sha1", metaVar = "SHA1")
String sha1
void run() {
BranchInput branch = new BranchInput()
branch.revision = sha1
api.projects().name(projectName).branch(branchName).create(branch)
stdout.println("Branch created: " + branchName)
}
}
^D
https://gist.github.com/lucamilanesio/9687118
25
Script classes get
Plugins Guice
Injections
(but cannot add Guice Modules)
26
List projects via REST API
$ cat - > ~/gerrit/plugins/projects-1.0.scala
import com.google.inject._
import com.google.gerrit.extensions.annotations._
import com.google.gerrit.server.project._
import javax.servlet.http._
import scala.collection.JavaConversions._
@Singleton @Export("/")
class Projects @Inject() (val pc: ProjectCache) extends HttpServlet {
override def doGet(req: HttpServletRequest, resp: HttpServletResponse) =
resp.getWriter print
"[" +
(pc.all map ( """ + _.get + """ ) mkString ",") +
"]"
}
^D
https://gist.github.com/lucamilanesio/9687133
27
Scala is
COMPACT + FUNCTIONAL
NOTE: for Guice injection
@Inject() before constructor vals
28
FUNCTIONAL
IS PERFECT
FOR …
29
Scalable in-process hooks
$ cat - > ~/gerrit/plugins/inprochook-1.0.scala
import org.slf4j.LoggerFactory._
import com.google.inject._
import com.google.gerrit.common._
import com.google.gerrit.server.events._
import com.google.gerrit.extensions.registration.DynamicSet
@Singleton
class ListenToChanges extends ChangeListener {
val log = getLogger(classOf[ListenToChanges])
override def onChangeEvent(e: ChangeEvent) = e match {
case comm: CommentAddedEvent =>
log info s"${comm.author.name} said '${comm.comment}' " +
s"on ${comm.change.project}/${comm.change.number}'"
case _ =>
}
}
class HooksModule extends AbstractModule {
override def configure =
DynamicSet bind(binder, classOf[ChangeListener]) to classOf[ListenToChanges]
}
^D
 Less CPU overhead (no exec/fork)  faster and scalable
 Works on behalf of user thread identity
 Access Gerrit injected objects (Cache, ReviewDb, JGit)
https://gist.github.com/lucamilanesio/9687154
30
Commit message validation
$ cat - > ~/gerrit/plugins/commitheadline-1.0.scala
import scala.collection.JavaConversions._
import com.google.inject._
import com.google.gerrit.extensions.annotations._
import com.google.gerrit.server.git.validators._
import com.google.gerrit.server.events._
@Singleton
@Listen
class HasIssueInCommitHeadline extends CommitValidationListener {
override def onCommitReceived(e: CommitReceivedEvent) =
"[A-Z]+-[0-9]+".r findFirstIn e.commit.getShortMessage map {
issue => Seq(new CommitValidationMessage(s"Issue: $issue", false))
} getOrElse {
throw new CommitValidationException("Missing JIRA-ID in commit headline")
}
}
^D
 Native pattern-matching support
 Java regex available out-of-the box
 Support for Optional values (map/getOrElse)
https://gist.github.com/lucamilanesio/9687174
31
And there is more …
audit events
download commands
project and group events
message of the day
Prolog predicates
auth backends
avatars
32
WHEN scripting plugins will be included in Gerrit ?
Hackathon #6
24-26th March we will keep
on hacking on Gerrit
MISSION:
improve, stabilise and
merge scripting plugins into
Gerrit master !
TARGET VERSION:
Gerrit Ver. 2.10 (?)
33
Try it on-line (with scripting): http://gerrithub.io/login
Read the Gerrit book: http://gerrithub.io/book
Keep in touch: http://gitenterprise.me
Learn more about Gerrit with
20% OFF Book discount for
Gerrit User Summit 2014
Book PROMO-CODE: LGCRB20
eBook PROMO-CODE: LGCReB20

Más contenido relacionado

La actualidad más candente

SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in JavaIonut Bilica
 
Lezione12: Autenticazione e gestione delle sessioni in REST
Lezione12: Autenticazione e gestione delle sessioni in RESTLezione12: Autenticazione e gestione delle sessioni in REST
Lezione12: Autenticazione e gestione delle sessioni in RESTAndrea Della Corte
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignVictor Rentea
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultBram Vogelaar
 
What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0Luca Milanesio
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
 
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...Edureka!
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next ChapterVictor Rentea
 
Keep your code clean
Keep your code cleanKeep your code clean
Keep your code cleanmacrochen
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable codeGeshan Manandhar
 
Inline and lambda function
Inline and lambda functionInline and lambda function
Inline and lambda functionJawad Khan
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithVictor Rentea
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net coreSam Nasr, MCSA, MVP
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An IntroductionSam Brannen
 

La actualidad más candente (20)

Clean code
Clean codeClean code
Clean code
 
Using Specflow for BDD
Using Specflow for BDDUsing Specflow for BDD
Using Specflow for BDD
 
GDSC - Introduction to GIT
GDSC - Introduction to GITGDSC - Introduction to GIT
GDSC - Introduction to GIT
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Lezione12: Autenticazione e gestione delle sessioni in REST
Lezione12: Autenticazione e gestione delle sessioni in RESTLezione12: Autenticazione e gestione delle sessioni in REST
Lezione12: Autenticazione e gestione delle sessioni in REST
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
 
What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next Chapter
 
Keep your code clean
Keep your code cleanKeep your code clean
Keep your code clean
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
Inline and lambda function
Inline and lambda functionInline and lambda function
Inline and lambda function
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Jdbc
Jdbc   Jdbc
Jdbc
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An Introduction
 

Destacado

Gerrit Code Review Analytics
Gerrit Code Review AnalyticsGerrit Code Review Analytics
Gerrit Code Review AnalyticsLuca Milanesio
 
Speed up Continuous Delivery with BigData Analytics
Speed up Continuous Delivery with BigData AnalyticsSpeed up Continuous Delivery with BigData Analytics
Speed up Continuous Delivery with BigData AnalyticsLuca Milanesio
 
Mobile Application Lifecycle with Jekins, Trello and CollabNet TeamForge
Mobile Application Lifecycle with Jekins, Trello and CollabNet TeamForgeMobile Application Lifecycle with Jekins, Trello and CollabNet TeamForge
Mobile Application Lifecycle with Jekins, Trello and CollabNet TeamForgeLuca Milanesio
 
Gerrit jenkins-big data-continuous-delivery
Gerrit jenkins-big data-continuous-deliveryGerrit jenkins-big data-continuous-delivery
Gerrit jenkins-big data-continuous-deliveryLuca Milanesio
 
Git workshop 33degree 2011 krakow
Git workshop 33degree 2011 krakowGit workshop 33degree 2011 krakow
Git workshop 33degree 2011 krakowLuca Milanesio
 
GitBlit plugin for Gerrit Code Review
GitBlit plugin for Gerrit Code ReviewGitBlit plugin for Gerrit Code Review
GitBlit plugin for Gerrit Code ReviewLuca Milanesio
 
GerritHub.io - present, past, future
GerritHub.io - present, past, futureGerritHub.io - present, past, future
GerritHub.io - present, past, futureLuca Milanesio
 
Devoxx 2016 Using Jenkins, Gerrit and Spark for Continuous Delivery Analytics
Devoxx 2016 Using Jenkins, Gerrit and Spark for Continuous Delivery AnalyticsDevoxx 2016 Using Jenkins, Gerrit and Spark for Continuous Delivery Analytics
Devoxx 2016 Using Jenkins, Gerrit and Spark for Continuous Delivery AnalyticsLuca Milanesio
 
Zero-Downtime Gerrit Code Review Upgrade
Zero-Downtime Gerrit Code Review UpgradeZero-Downtime Gerrit Code Review Upgrade
Zero-Downtime Gerrit Code Review UpgradeLuca Milanesio
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerLuca Milanesio
 
Jenkins User Conference - Continuous Delivery on Mobile
Jenkins User Conference - Continuous Delivery on MobileJenkins User Conference - Continuous Delivery on Mobile
Jenkins User Conference - Continuous Delivery on MobileLuca Milanesio
 

Destacado (12)

Gerrit Code Review Analytics
Gerrit Code Review AnalyticsGerrit Code Review Analytics
Gerrit Code Review Analytics
 
Speed up Continuous Delivery with BigData Analytics
Speed up Continuous Delivery with BigData AnalyticsSpeed up Continuous Delivery with BigData Analytics
Speed up Continuous Delivery with BigData Analytics
 
Mobile Application Lifecycle with Jekins, Trello and CollabNet TeamForge
Mobile Application Lifecycle with Jekins, Trello and CollabNet TeamForgeMobile Application Lifecycle with Jekins, Trello and CollabNet TeamForge
Mobile Application Lifecycle with Jekins, Trello and CollabNet TeamForge
 
Gerrit jenkins-big data-continuous-delivery
Gerrit jenkins-big data-continuous-deliveryGerrit jenkins-big data-continuous-delivery
Gerrit jenkins-big data-continuous-delivery
 
Git workshop 33degree 2011 krakow
Git workshop 33degree 2011 krakowGit workshop 33degree 2011 krakow
Git workshop 33degree 2011 krakow
 
Is TDD dead or alive?
Is TDD dead or alive?Is TDD dead or alive?
Is TDD dead or alive?
 
GitBlit plugin for Gerrit Code Review
GitBlit plugin for Gerrit Code ReviewGitBlit plugin for Gerrit Code Review
GitBlit plugin for Gerrit Code Review
 
GerritHub.io - present, past, future
GerritHub.io - present, past, futureGerritHub.io - present, past, future
GerritHub.io - present, past, future
 
Devoxx 2016 Using Jenkins, Gerrit and Spark for Continuous Delivery Analytics
Devoxx 2016 Using Jenkins, Gerrit and Spark for Continuous Delivery AnalyticsDevoxx 2016 Using Jenkins, Gerrit and Spark for Continuous Delivery Analytics
Devoxx 2016 Using Jenkins, Gerrit and Spark for Continuous Delivery Analytics
 
Zero-Downtime Gerrit Code Review Upgrade
Zero-Downtime Gerrit Code Review UpgradeZero-Downtime Gerrit Code Review Upgrade
Zero-Downtime Gerrit Code Review Upgrade
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and Docker
 
Jenkins User Conference - Continuous Delivery on Mobile
Jenkins User Conference - Continuous Delivery on MobileJenkins User Conference - Continuous Delivery on Mobile
Jenkins User Conference - Continuous Delivery on Mobile
 

Similar a Gerrit Code Review: how to script a plugin with Scala and Groovy

Introduction to git and Github
Introduction to git and GithubIntroduction to git and Github
Introduction to git and GithubWycliff1
 
FOSDEM 2017: GitLab CI
FOSDEM 2017:  GitLab CIFOSDEM 2017:  GitLab CI
FOSDEM 2017: GitLab CIOlinData
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger
 
Gitlab Training with GIT and SourceTree
Gitlab Training with GIT and SourceTreeGitlab Training with GIT and SourceTree
Gitlab Training with GIT and SourceTreeTeerapat Khunpech
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacriptLei Kang
 
Managing Github via Terrafom.pdf
Managing Github via Terrafom.pdfManaging Github via Terrafom.pdf
Managing Github via Terrafom.pdfmicharaeck
 
git github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxgit github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxAbelPhilipJoseph
 
GIT training - advanced for software projects
GIT training - advanced for software projectsGIT training - advanced for software projects
GIT training - advanced for software projectsThierry Gayet
 
2015-ghci-presentation-git_gerritJenkins_final
2015-ghci-presentation-git_gerritJenkins_final2015-ghci-presentation-git_gerritJenkins_final
2015-ghci-presentation-git_gerritJenkins_finalMythri P K
 
Openstack contribution process
Openstack contribution processOpenstack contribution process
Openstack contribution processSyed Armani
 
OpenStack Contribution Process
OpenStack Contribution ProcessOpenStack Contribution Process
OpenStack Contribution Processopenstackindia
 
Gitlab ci, cncf.sk
Gitlab ci, cncf.skGitlab ci, cncf.sk
Gitlab ci, cncf.skJuraj Hantak
 
introductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdfintroductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdfBruceLee275640
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control SystemVictor Wong
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and githubAderemi Dadepo
 

Similar a Gerrit Code Review: how to script a plugin with Scala and Groovy (20)

GIT By Sivakrishna
GIT By SivakrishnaGIT By Sivakrishna
GIT By Sivakrishna
 
Github By Nyros Developer
Github By Nyros DeveloperGithub By Nyros Developer
Github By Nyros Developer
 
Introduction to git and Github
Introduction to git and GithubIntroduction to git and Github
Introduction to git and Github
 
FOSDEM 2017: GitLab CI
FOSDEM 2017:  GitLab CIFOSDEM 2017:  GitLab CI
FOSDEM 2017: GitLab CI
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010
 
GDSC GIT AND GITHUB
GDSC GIT AND GITHUB GDSC GIT AND GITHUB
GDSC GIT AND GITHUB
 
Gitlab Training with GIT and SourceTree
Gitlab Training with GIT and SourceTreeGitlab Training with GIT and SourceTree
Gitlab Training with GIT and SourceTree
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacript
 
Managing Github via Terrafom.pdf
Managing Github via Terrafom.pdfManaging Github via Terrafom.pdf
Managing Github via Terrafom.pdf
 
git github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxgit github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptx
 
GIT training - advanced for software projects
GIT training - advanced for software projectsGIT training - advanced for software projects
GIT training - advanced for software projects
 
2015-ghci-presentation-git_gerritJenkins_final
2015-ghci-presentation-git_gerritJenkins_final2015-ghci-presentation-git_gerritJenkins_final
2015-ghci-presentation-git_gerritJenkins_final
 
Openstack contribution process
Openstack contribution processOpenstack contribution process
Openstack contribution process
 
OpenStack Contribution Process
OpenStack Contribution ProcessOpenStack Contribution Process
OpenStack Contribution Process
 
Gitlab ci, cncf.sk
Gitlab ci, cncf.skGitlab ci, cncf.sk
Gitlab ci, cncf.sk
 
GWT Contributor Workshop
GWT Contributor WorkshopGWT Contributor Workshop
GWT Contributor Workshop
 
introductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdfintroductiontogitandgithub-120702044048-phpapp01.pdf
introductiontogitandgithub-120702044048-phpapp01.pdf
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and github
 

Más de Luca Milanesio

What's new in Gerrit Code Review v3.1 and beyond
What's new in Gerrit Code Review v3.1 and beyondWhat's new in Gerrit Code Review v3.1 and beyond
What's new in Gerrit Code Review v3.1 and beyondLuca Milanesio
 
Gerrit Analytics applied to Android source code
Gerrit Analytics applied to Android source codeGerrit Analytics applied to Android source code
Gerrit Analytics applied to Android source codeLuca Milanesio
 
Cloud-native Gerrit Code Review
Cloud-native Gerrit Code ReviewCloud-native Gerrit Code Review
Cloud-native Gerrit Code ReviewLuca Milanesio
 
Gerrit Code Review migrations step-by-step
Gerrit Code Review migrations step-by-stepGerrit Code Review migrations step-by-step
Gerrit Code Review migrations step-by-stepLuca Milanesio
 
Gerrit Code Review v3.2 and v3.3
Gerrit Code Review v3.2 and v3.3Gerrit Code Review v3.2 and v3.3
Gerrit Code Review v3.2 and v3.3Luca Milanesio
 
ChronicleMap non-blocking cache for Gerrit v3.3
ChronicleMap non-blocking cache for Gerrit v3.3ChronicleMap non-blocking cache for Gerrit v3.3
ChronicleMap non-blocking cache for Gerrit v3.3Luca Milanesio
 
Gerrit Code Review multi-site
Gerrit Code Review multi-siteGerrit Code Review multi-site
Gerrit Code Review multi-siteLuca Milanesio
 
Gerrit User Summit 2019 Keynote
Gerrit User Summit 2019 KeynoteGerrit User Summit 2019 Keynote
Gerrit User Summit 2019 KeynoteLuca Milanesio
 
Gerrit multi-master / multi-site at GerritHub
Gerrit multi-master / multi-site at GerritHubGerrit multi-master / multi-site at GerritHub
Gerrit multi-master / multi-site at GerritHubLuca Milanesio
 
GerritHub a true Gerrit migration story to v2.15
GerritHub a true Gerrit migration story to v2.15GerritHub a true Gerrit migration story to v2.15
GerritHub a true Gerrit migration story to v2.15Luca Milanesio
 
Gerrit User Summit 2018 - Keynote
Gerrit User Summit 2018 - Keynote Gerrit User Summit 2018 - Keynote
Gerrit User Summit 2018 - Keynote Luca Milanesio
 
Jenkins plugin for Gerrit Code Review pipelines
Jenkins plugin for Gerrit Code Review pipelinesJenkins plugin for Gerrit Code Review pipelines
Jenkins plugin for Gerrit Code Review pipelinesLuca Milanesio
 
Gerrit User Summit 2017 Keynote
Gerrit User Summit 2017 KeynoteGerrit User Summit 2017 Keynote
Gerrit User Summit 2017 KeynoteLuca Milanesio
 
How to keep Jenkins logs forever without performance issues
How to keep Jenkins logs forever without performance issuesHow to keep Jenkins logs forever without performance issues
How to keep Jenkins logs forever without performance issuesLuca Milanesio
 
Jenkins Pipeline on your Local Box to Reduce Cycle Time
Jenkins Pipeline on your Local Box to Reduce Cycle TimeJenkins Pipeline on your Local Box to Reduce Cycle Time
Jenkins Pipeline on your Local Box to Reduce Cycle TimeLuca Milanesio
 
Jenkins world 2017 - Data-Driven CI Pipeline with Gerrit Code Review
Jenkins world 2017 - Data-Driven CI Pipeline with Gerrit Code ReviewJenkins world 2017 - Data-Driven CI Pipeline with Gerrit Code Review
Jenkins world 2017 - Data-Driven CI Pipeline with Gerrit Code ReviewLuca Milanesio
 
Stable master workflow with Gerrit Code Review
Stable master workflow with Gerrit Code ReviewStable master workflow with Gerrit Code Review
Stable master workflow with Gerrit Code ReviewLuca Milanesio
 

Más de Luca Milanesio (17)

What's new in Gerrit Code Review v3.1 and beyond
What's new in Gerrit Code Review v3.1 and beyondWhat's new in Gerrit Code Review v3.1 and beyond
What's new in Gerrit Code Review v3.1 and beyond
 
Gerrit Analytics applied to Android source code
Gerrit Analytics applied to Android source codeGerrit Analytics applied to Android source code
Gerrit Analytics applied to Android source code
 
Cloud-native Gerrit Code Review
Cloud-native Gerrit Code ReviewCloud-native Gerrit Code Review
Cloud-native Gerrit Code Review
 
Gerrit Code Review migrations step-by-step
Gerrit Code Review migrations step-by-stepGerrit Code Review migrations step-by-step
Gerrit Code Review migrations step-by-step
 
Gerrit Code Review v3.2 and v3.3
Gerrit Code Review v3.2 and v3.3Gerrit Code Review v3.2 and v3.3
Gerrit Code Review v3.2 and v3.3
 
ChronicleMap non-blocking cache for Gerrit v3.3
ChronicleMap non-blocking cache for Gerrit v3.3ChronicleMap non-blocking cache for Gerrit v3.3
ChronicleMap non-blocking cache for Gerrit v3.3
 
Gerrit Code Review multi-site
Gerrit Code Review multi-siteGerrit Code Review multi-site
Gerrit Code Review multi-site
 
Gerrit User Summit 2019 Keynote
Gerrit User Summit 2019 KeynoteGerrit User Summit 2019 Keynote
Gerrit User Summit 2019 Keynote
 
Gerrit multi-master / multi-site at GerritHub
Gerrit multi-master / multi-site at GerritHubGerrit multi-master / multi-site at GerritHub
Gerrit multi-master / multi-site at GerritHub
 
GerritHub a true Gerrit migration story to v2.15
GerritHub a true Gerrit migration story to v2.15GerritHub a true Gerrit migration story to v2.15
GerritHub a true Gerrit migration story to v2.15
 
Gerrit User Summit 2018 - Keynote
Gerrit User Summit 2018 - Keynote Gerrit User Summit 2018 - Keynote
Gerrit User Summit 2018 - Keynote
 
Jenkins plugin for Gerrit Code Review pipelines
Jenkins plugin for Gerrit Code Review pipelinesJenkins plugin for Gerrit Code Review pipelines
Jenkins plugin for Gerrit Code Review pipelines
 
Gerrit User Summit 2017 Keynote
Gerrit User Summit 2017 KeynoteGerrit User Summit 2017 Keynote
Gerrit User Summit 2017 Keynote
 
How to keep Jenkins logs forever without performance issues
How to keep Jenkins logs forever without performance issuesHow to keep Jenkins logs forever without performance issues
How to keep Jenkins logs forever without performance issues
 
Jenkins Pipeline on your Local Box to Reduce Cycle Time
Jenkins Pipeline on your Local Box to Reduce Cycle TimeJenkins Pipeline on your Local Box to Reduce Cycle Time
Jenkins Pipeline on your Local Box to Reduce Cycle Time
 
Jenkins world 2017 - Data-Driven CI Pipeline with Gerrit Code Review
Jenkins world 2017 - Data-Driven CI Pipeline with Gerrit Code ReviewJenkins world 2017 - Data-Driven CI Pipeline with Gerrit Code Review
Jenkins world 2017 - Data-Driven CI Pipeline with Gerrit Code Review
 
Stable master workflow with Gerrit Code Review
Stable master workflow with Gerrit Code ReviewStable master workflow with Gerrit Code Review
Stable master workflow with Gerrit Code Review
 

Último

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Último (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

Gerrit Code Review: how to script a plugin with Scala and Groovy

  • 2. 2 About Luca • Luca Milanesio Co-founder of GerritForge • over 20 years of experience in Agile Development SCM, CI and ALM worldwide • Contributor to Jenkins since 2007 (and previously Hudson) • Git SCM mentor for the Enterprise since 2009 • Contributor to Gerrit Code Review community since 2011
  • 3. 3 About GerritForge Founded in 2009 in London UK Mission: Agile Enterprise Products:
  • 4. 4 Agenda  Where we come from ?  2 years ago: Gerrit plugins  We want more plugins  Create a plugin in 60 seconds  What, how and when are coming?  Plugins showcase
  • 6. 6 Why don’t we introduce plugins ? They have been so successful with Jenkins
  • 7. 7 Gerrit Hackathon 7th of May 2012 The first “helloworld” plugin was born
  • 8. 8 WHO REMEMBERS THIS ? Gerrit Summit 2012 Ver. 2.5.x
  • 10. 10 Can we do more ? Let's ask Jenkins 
  • 13. 13 That would be very useful for Gerrit Administrators to be able to write quick automation scripts for their daily tasks. I would prioritize groovy plugin more for the popularity of groovy scripting. I think adding a "scripting language plugin" to support plugins written in scripting languages is a very good idea Hi all, I was thinking about extending Gerrit capabilities to load plugins / extensions by providing "wrapper" for other JVM languages. So … we asked the Community I would prefer scala, because I've already written my plugins with it. imho the builld process is the main impediment.
  • 15. 15 NO STEPS, NO BUILD … just do it ! $ cat - > ~/gerrit/plugins/hello-1.0.groovy import com.google.gerrit.sshd.* import com.google.gerrit.extensions.annotations.* @Export("groovy") class GroovyCommand extends SshCommand { public void run() { stdout.println "Hi from Groovy" } } ^D This sample has 190 chars: you need to type at least 3.2 chars/sec to complete the sample in only one minute  https://gist.github.com/lucamilanesio/9687053
  • 16. 16 IS THAT TRUE ? Let’s check on Gerrit $ ssh –p 29418 user@localhost gerrit plugin ls Name Version Status File ---------------------------------------------------------------------- hello 1.0 ENABLED hello-1.0.groovy Gerrit auto-detects the new Groovy file under $GERRIT_SITE/plugins, invoke the interpreter and auto-wrap the class into a self-contained Gerrit plugin. Groovy class is compiled into byte-code BUT is slower than native Java plugin.
  • 17. 17 DOES IT REALLY WORK ? $ ssh –p 29418 user@localhost hello groovy Hi from Groovy No magic … IT IS ALL REAL ! Plugin name (hello) comes from the script filename. A new SSH command (groovy) has been defined in Gerrit associated to the Groovy script loaded.
  • 18. 18 What about Scala ? Just do it again ! $ cat - > ~/gerrit/plugins/hi-1.0.scala import com.google.gerrit.sshd._ import com.google.gerrit.extensions.annotations._ @Export("scala") class ScalaCommand extends SshCommand { override def run = stdout println "Hi from Scala" } ^D Scala is more concise with just 178 chars : you can take it easy with 2.9 chars/sec to type it a minute  https://gist.github.com/lucamilanesio/9687092
  • 19. 19 You have now two plugins loaded $ ssh –p 29418 user@localhost gerrit plugin ls Name Version Status File ---------------------------------------------------------------------- hello 1.0 ENABLED hello-1.0.groovy hi 1.0 ENABLED hi-1.0.scala There are no differences for Gerrit between Java, Groovy or Scala plugins: they have the same dignity and power. Scala compiler takes longer but byte-code runs at the same speed as a native Java plugin!
  • 20. 20 Reactions from the Gerrit mailing list … So i checked it out and tried it, and what should i say ... Wow, it rocks! ;-) Combined with new and shiny Plugin API the code is really short. So i started new repo on gh [1] and created two working plugins [2], [3], and sure would add more, so to say, cookbook-groovy-plugin: $>ssh gerrit review approve I59302cbb $>Approve change: I59302cbb. What do YOU think ? 
  • 21. 21 WHAT can scripting plugins do now ? 1. Define new SSH commands 2. Define new REST APIs 3. Listen to Gerrit events
  • 22. 22 HOW can I get Gerrit with scripting plugins ? Download the Gerrit master with scripting extensions from: http://ci.gerritforge.com/job/Gerrit-master-scripting/lastSuccessfulBuild/artifact/buck- out/gen/gerrit-scripting.war Run Gerrit init and say Y for installing the Scala and Groovy scripting plugins providers: *** Plugins *** Install plugin groovy-provider version v2.9-rc1-325-g96d0d43 [y/N]? Y Install plugin scala-provider version v2.9-rc1-325-g96d0d43 [y/N]? y You may want to increase the JVM PermGen on gerrit.config when loading/unloading scripting plugins [container] javaOptions = -XX:MaxPermSize=1024m
  • 24. 24 Create a branch through Gerrit API $ cat - > ~/gerrit/plugins/branch-1.0.groovy import com.google.gerrit.sshd.* import com.google.gerrit.extensions.annotations.* import com.google.gerrit.extensions.api.* import com.google.gerrit.extensions.api.projects.* import com.google.inject.* import org.kohsuke.args4j.* @Export("create") @CommandMetaData(name = "create-branch", description = "Create branch") class CreateBranch extends SshCommand { @Inject GerritApi api @Argument(index = 0, usage = "Project name", metaVar = "PROJECT") String projectName @Argument(index = 1, usage = "Branch name", metaVar = "BRANCH") String branchName @Argument(index = 2, usage = "Branch point sha1", metaVar = "SHA1") String sha1 void run() { BranchInput branch = new BranchInput() branch.revision = sha1 api.projects().name(projectName).branch(branchName).create(branch) stdout.println("Branch created: " + branchName) } } ^D https://gist.github.com/lucamilanesio/9687118
  • 25. 25 Script classes get Plugins Guice Injections (but cannot add Guice Modules)
  • 26. 26 List projects via REST API $ cat - > ~/gerrit/plugins/projects-1.0.scala import com.google.inject._ import com.google.gerrit.extensions.annotations._ import com.google.gerrit.server.project._ import javax.servlet.http._ import scala.collection.JavaConversions._ @Singleton @Export("/") class Projects @Inject() (val pc: ProjectCache) extends HttpServlet { override def doGet(req: HttpServletRequest, resp: HttpServletResponse) = resp.getWriter print "[" + (pc.all map ( """ + _.get + """ ) mkString ",") + "]" } ^D https://gist.github.com/lucamilanesio/9687133
  • 27. 27 Scala is COMPACT + FUNCTIONAL NOTE: for Guice injection @Inject() before constructor vals
  • 29. 29 Scalable in-process hooks $ cat - > ~/gerrit/plugins/inprochook-1.0.scala import org.slf4j.LoggerFactory._ import com.google.inject._ import com.google.gerrit.common._ import com.google.gerrit.server.events._ import com.google.gerrit.extensions.registration.DynamicSet @Singleton class ListenToChanges extends ChangeListener { val log = getLogger(classOf[ListenToChanges]) override def onChangeEvent(e: ChangeEvent) = e match { case comm: CommentAddedEvent => log info s"${comm.author.name} said '${comm.comment}' " + s"on ${comm.change.project}/${comm.change.number}'" case _ => } } class HooksModule extends AbstractModule { override def configure = DynamicSet bind(binder, classOf[ChangeListener]) to classOf[ListenToChanges] } ^D  Less CPU overhead (no exec/fork)  faster and scalable  Works on behalf of user thread identity  Access Gerrit injected objects (Cache, ReviewDb, JGit) https://gist.github.com/lucamilanesio/9687154
  • 30. 30 Commit message validation $ cat - > ~/gerrit/plugins/commitheadline-1.0.scala import scala.collection.JavaConversions._ import com.google.inject._ import com.google.gerrit.extensions.annotations._ import com.google.gerrit.server.git.validators._ import com.google.gerrit.server.events._ @Singleton @Listen class HasIssueInCommitHeadline extends CommitValidationListener { override def onCommitReceived(e: CommitReceivedEvent) = "[A-Z]+-[0-9]+".r findFirstIn e.commit.getShortMessage map { issue => Seq(new CommitValidationMessage(s"Issue: $issue", false)) } getOrElse { throw new CommitValidationException("Missing JIRA-ID in commit headline") } } ^D  Native pattern-matching support  Java regex available out-of-the box  Support for Optional values (map/getOrElse) https://gist.github.com/lucamilanesio/9687174
  • 31. 31 And there is more … audit events download commands project and group events message of the day Prolog predicates auth backends avatars
  • 32. 32 WHEN scripting plugins will be included in Gerrit ? Hackathon #6 24-26th March we will keep on hacking on Gerrit MISSION: improve, stabilise and merge scripting plugins into Gerrit master ! TARGET VERSION: Gerrit Ver. 2.10 (?)
  • 33. 33
  • 34. Try it on-line (with scripting): http://gerrithub.io/login Read the Gerrit book: http://gerrithub.io/book Keep in touch: http://gitenterprise.me Learn more about Gerrit with 20% OFF Book discount for Gerrit User Summit 2014 Book PROMO-CODE: LGCRB20 eBook PROMO-CODE: LGCReB20