Skip to content

Commit 1996e6a

Browse files
committed
Add new examples and update metadata for upcoming Gitblit 1.5.0 release
1 parent 541dc77 commit 1996e6a

File tree

8 files changed

+187
-20
lines changed

8 files changed

+187
-20
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
Cookbook Gitblit plugin
1+
## Gitblit Cookbook plugin
22

3-
This plugin currently depends on this change [1].
3+
This plugin provides example implementations of all Gitblit extension points.
4+
5+
### Building, Deploying, Testing
46

57
To build, apply the changes and execute:
68

79
```
8-
mvn package
10+
mvn clean package
911
```
1012

11-
To deploy, create directory `${baseFolder}/plugins` and put the
12-
cookbook-1.0.zip in this directory.
13+
To deploy, copy the generated cookbook zip file to your Gitblit `${baseFolder}/plugins` directory.
1314

14-
To test, execute:
15+
To test, restart Gitblit and execute:
1516

1617
```
17-
$ ssh gitblit cookbook hello --french "'tout le monde'"
18+
$ ssh hostname -l username -p 29418 cookbook hello --french "'tout le monde'"
1819
Bonjour tout le monde!
1920
```
2021

21-
* [1] https://dev.gitblit.com/tickets/gitblit.git/6

pom.xml

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6+
<name>Gitblit Cookbook plugin</name>
67
<groupId>com.gitblit.plugins</groupId>
78
<artifactId>cookbook</artifactId>
8-
<version>1.0</version>
9+
<version>1.1.0-SNAPSHOT</version>
910
<packaging>jar</packaging>
10-
<name>GitBlit Cookbook plugin</name>
1111

1212
<properties>
13-
<plugin.id>cookbook</plugin.id>
14-
<plugin.class>com.gitblit.plugins.cookbook.GitblitCookbookPlugin</plugin.class>
15-
<plugin.version>1.0</plugin.version>
13+
<plugin.id>${project.artifactId}</plugin.id>
14+
<plugin.description>${project.name}</plugin.description>
15+
<plugin.class>com.gitblit.plugin.cookbook.Plugin</plugin.class>
16+
<plugin.version>${project.version}</plugin.version>
1617
<plugin.provider>David Ostrovsky</plugin.provider>
1718
<plugin.dependencies />
1819
</properties>
@@ -135,6 +136,7 @@
135136
<archive>
136137
<manifestEntries>
137138
<Plugin-Id>${plugin.id}</Plugin-Id>
139+
<Plugin-Description>${plugin.description}</Plugin-Description>
138140
<Plugin-Class>${plugin.class}</Plugin-Class>
139141
<Plugin-Version>${plugin.version}</Plugin-Version>
140142
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
@@ -159,7 +161,7 @@
159161
<dependency>
160162
<groupId>com.gitblit</groupId>
161163
<artifactId>gitblit</artifactId>
162-
<version>1.4.2-SNAPSHOT</version>
164+
<version>1.5.0-SNAPSHOT</version>
163165
<scope>provided</scope>
164166
</dependency>
165167
</dependencies>

src/main/java/com/gitblit/plugins/cookbook/HelloWorldCommand.java src/main/java/com/gitblit/plugin/cookbook/HelloWorldCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.gitblit.plugins.cookbook;
16+
package com.gitblit.plugin.cookbook;
1717

1818
import org.kohsuke.args4j.Argument;
1919
import org.kohsuke.args4j.Option;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2014 gitblit.com.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.gitblit.plugin.cookbook;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
21+
import ro.fortsoft.pf4j.Extension;
22+
23+
import com.gitblit.extensions.PatchsetHook;
24+
import com.gitblit.models.TicketModel;
25+
26+
/**
27+
*
28+
* Example patchset hook.
29+
*
30+
* @author James Moger
31+
*
32+
*/
33+
@Extension
34+
public class MyPatchsetHook extends PatchsetHook {
35+
36+
final Logger log = LoggerFactory.getLogger(getClass());
37+
38+
@Override
39+
public void onNewPatchset(TicketModel ticket) {
40+
log.info(String.format("%s new patchset %s ticket-%d patchset %d",
41+
getClass().getSimpleName(), ticket.repository, ticket.number,
42+
ticket.getCurrentPatchset().number));
43+
}
44+
45+
@Override
46+
public void onUpdatePatchset(TicketModel ticket) {
47+
log.info(String.format("%s update patchset %s ticket-%d patchset %d-%d",
48+
getClass().getSimpleName(), ticket.repository, ticket.number,
49+
ticket.getCurrentPatchset().number,
50+
ticket.getCurrentPatchset().rev));
51+
}
52+
53+
@Override
54+
public void onMergePatchset(TicketModel ticket) {
55+
log.info(String.format("%s merge patchset %s ticket-%d SHA %s",
56+
getClass().getSimpleName(), ticket.repository, ticket.number,
57+
ticket.mergeSha));
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2014 gitblit.com.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.gitblit.plugin.cookbook;
17+
18+
import java.util.Collection;
19+
20+
import org.eclipse.jgit.transport.ReceiveCommand;
21+
22+
import ro.fortsoft.pf4j.Extension;
23+
24+
import com.gitblit.extensions.ReceiveHook;
25+
import com.gitblit.git.GitblitReceivePack;
26+
import com.gitblit.models.RepositoryModel;
27+
import com.gitblit.models.UserModel;
28+
29+
/**
30+
* Example receive hook.
31+
*
32+
* @author James Moger
33+
*
34+
*/
35+
@Extension
36+
public class MyReceiveHook extends ReceiveHook {
37+
38+
@Override
39+
public void onPreReceive(GitblitReceivePack receivePack, Collection<ReceiveCommand> commands) {
40+
RepositoryModel repository = receivePack.getRepositoryModel();
41+
UserModel user = receivePack.getUserModel();
42+
receivePack.sendInfo("Hi {0}, I see {1} ref commands onPreReceive for {2}",
43+
user.getDisplayName(),
44+
commands.size(),
45+
repository.name);
46+
}
47+
48+
@Override
49+
public void onPostReceive(GitblitReceivePack receivePack, Collection<ReceiveCommand> commands) {
50+
RepositoryModel repository = receivePack.getRepositoryModel();
51+
UserModel user = receivePack.getUserModel();
52+
receivePack.sendInfo("Hi {0}, I see {1} ref commands onPostReceive for {2}",
53+
user.getDisplayName(),
54+
commands.size(),
55+
repository.name);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2014 gitblit.com.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.gitblit.plugin.cookbook;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
20+
import ro.fortsoft.pf4j.Extension;
21+
22+
import com.gitblit.extensions.TicketHook;
23+
import com.gitblit.models.TicketModel;
24+
import com.gitblit.models.TicketModel.Change;
25+
26+
/**
27+
* Example ticket hook.
28+
*
29+
* @author James Moger
30+
*
31+
*/
32+
@Extension
33+
public class MyTicketHook extends TicketHook {
34+
35+
final Logger log = LoggerFactory.getLogger(getClass());
36+
37+
@Override
38+
public void onNewTicket(TicketModel ticket) {
39+
log.info(String.format("%s %s ticket #%d created",
40+
getClass().getSimpleName(), ticket.repository, ticket.number));
41+
42+
}
43+
44+
@Override
45+
public void onUpdateTicket(TicketModel ticket, Change change) {
46+
log.info(String.format("%s %s ticket #%d updated",
47+
getClass().getSimpleName(), ticket.repository, ticket.number));
48+
}
49+
}

src/main/java/com/gitblit/plugins/cookbook/GitblitCookbookPlugin.java src/main/java/com/gitblit/plugin/cookbook/Plugin.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.gitblit.plugins.cookbook;
16+
package com.gitblit.plugin.cookbook;
1717

1818
import ro.fortsoft.pf4j.Extension;
19-
import ro.fortsoft.pf4j.Plugin;
2019
import ro.fortsoft.pf4j.PluginWrapper;
2120

21+
import com.gitblit.extensions.GitblitPlugin;
2222
import com.gitblit.models.UserModel;
2323
import com.gitblit.transport.ssh.commands.CommandMetaData;
2424
import com.gitblit.transport.ssh.commands.DispatchCommand;
2525

26-
public class GitblitCookbookPlugin extends Plugin {
26+
public class Plugin extends GitblitPlugin {
2727

28-
public GitblitCookbookPlugin(PluginWrapper wrapper) {
28+
public Plugin(PluginWrapper wrapper) {
2929
super(wrapper);
3030
}
3131

src/main/java/com/gitblit/plugins/cookbook/StatusCommand.java src/main/java/com/gitblit/plugin/cookbook/StatusCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.gitblit.plugins.cookbook;
16+
package com.gitblit.plugin.cookbook;
1717

1818
import com.gitblit.manager.IGitblit;
1919
import com.gitblit.models.ServerStatus;

0 commit comments

Comments
 (0)