├── .github └── FUNDING.yml ├── src ├── main │ ├── resources │ │ ├── static │ │ │ ├── repository │ │ │ │ ├── repository.css │ │ │ │ ├── repository.vm │ │ │ │ └── repository.js │ │ │ ├── img │ │ │ │ ├── pluginIcon.png │ │ │ │ └── pluginLogo.png │ │ │ ├── changelog_html.mustache │ │ │ └── admin │ │ │ │ ├── admin.css │ │ │ │ ├── admin.js │ │ │ │ └── admin.vm │ │ └── atlassian-plugin.xml │ └── java │ │ └── se │ │ └── bjurr │ │ └── changelog │ │ └── bitbucket │ │ ├── settings │ │ ├── AdminFormError.java │ │ ├── ValidationException.java │ │ ├── AdminFormValues.java │ │ ├── ChangelogSettingsBuilder.java │ │ ├── ChangelogSettings.java │ │ └── SettingsStorage.java │ │ ├── presentation │ │ ├── dto │ │ │ └── ChangelogDTO.java │ │ ├── RepositoryServlet.java │ │ ├── AdminServlet.java │ │ ├── ConfigResource.java │ │ └── RestResource.java │ │ └── application │ │ ├── ChangelogRepositoryService.java │ │ ├── JiraClientService.java │ │ └── ChangelogLibService.java └── test │ └── java │ └── se │ └── bjurr │ └── changelog │ └── bitbucket │ ├── settings │ └── SettingsStorageTest.java │ ├── application │ └── ChangelogRepositoryServiceTest.java │ └── presentation │ ├── RepositoryServletTest.java │ ├── ConfigResourceTest.java │ └── AdminServletTest.java ├── .gitignore ├── export_and_run.sh ├── release.sh ├── .travis.yml ├── setup-atlassian-sdk.sh ├── changelog.json ├── changelog.mustache ├── README.md ├── pom.xml ├── CHANGELOG.md └── LICENSE /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [tomasbjerre] 2 | -------------------------------------------------------------------------------- /src/main/resources/static/repository/repository.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .project 3 | .classpath 4 | .settings 5 | *~ 6 | .okhttpcache 7 | *iml 8 | -------------------------------------------------------------------------------- /src/main/resources/static/img/pluginIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasbjerre/git-changelog-bitbucket-plugin/HEAD/src/main/resources/static/img/pluginIcon.png -------------------------------------------------------------------------------- /src/main/resources/static/img/pluginLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasbjerre/git-changelog-bitbucket-plugin/HEAD/src/main/resources/static/img/pluginLogo.png -------------------------------------------------------------------------------- /export_and_run.sh: -------------------------------------------------------------------------------- 1 | export MAVEN_OPTS=-Dplugin.resource.directories=`pwd`/src/main/resources 2 | #atlas-mvn versions:update-properties 3 | atlas-run || mvn bitbucket:run 4 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #atlas-mvn versions:update-properties 3 | atlas-mvn release:prepare release:perform -B || exit 1 4 | ./build.sh 5 | git commit -a --amend --no-edit 6 | git push -f 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: java 3 | jdk: 4 | - oraclejdk8 5 | 6 | before_install: 7 | - ./setup-atlassian-sdk.sh `pwd` 8 | - export PATH=opt/atlassian-plugin-sdk/bin:opt/atlassian-plugin-sdk/apache-maven-*/bin:$PATH 9 | install: 10 | - atlas-mvn -q install -Dbitbucket.version=4.0.0 11 | - atlas-mvn -q install 12 | script: 13 | - atlas-package -q -Dbitbucket.version=4.0.0 14 | - atlas-package -q 15 | notifications: 16 | email: false 17 | -------------------------------------------------------------------------------- /setup-atlassian-sdk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$1" -gt "-1" ] 4 | then echo Give param, like /home/username 5 | fi 6 | 7 | installdir=$1 8 | cd $1 9 | wget https://marketplace.atlassian.com/download/plugins/atlassian-plugin-sdk-tgz 10 | mkdir opt 11 | tar -xvzf *plugin-sdk* -C opt 12 | mv opt/*plugin-sdk* opt/atlassian-plugin-sdk 13 | chmod a+x opt/atlassian-plugin-sdk/bin/* 14 | chmod a+x opt/atlassian-plugin-sdk/apache-maven-*/bin/* 15 | echo "export PATH=$installdir/opt/atlassian-plugin-sdk/bin:$installdir/opt/atlassian-plugin-sdk/apache-maven-*/bin:$PATH" >> ~/.bashrc 16 | source ~/.bashrc 17 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/settings/AdminFormError.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.settings; 2 | 3 | import javax.xml.bind.annotation.XmlAccessType; 4 | import javax.xml.bind.annotation.XmlAccessorType; 5 | import javax.xml.bind.annotation.XmlRootElement; 6 | 7 | @XmlRootElement 8 | @XmlAccessorType(XmlAccessType.FIELD) 9 | public class AdminFormError { 10 | private String field; 11 | private String error; 12 | 13 | public AdminFormError() { 14 | } 15 | 16 | public AdminFormError(String field, String error) { 17 | this.field = field; 18 | this.error = error; 19 | } 20 | 21 | public String getField() { 22 | return field; 23 | } 24 | 25 | public String getValue() { 26 | return error; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /changelog.json: -------------------------------------------------------------------------------- 1 | { 2 | "fromRepo": ".", 3 | "fromCommit": "0000000000000000000000000000000000000000", 4 | "toRef": "refs/heads/master", 5 | 6 | "ignoreCommitsIfMessageMatches": "^\\[maven-release-plugin\\].*|^\\[Gradle Release Plugin\\].*|^Merge.*", 7 | "readableTagName": "([0-9\\.]+)", 8 | "dateFormat": "YYYY-MM-dd HH:mm:ss", 9 | "untaggedName": "Next release", 10 | "noIssueName": "Other changes", 11 | "timeZone": "UTC", 12 | "removeIssueFromMessage": "true", 13 | 14 | "gitHubApi": "https://api.github.com/repos/tomasbjerre/git-changelog-bitbucket-plugin", 15 | "gitHubIssuePattern": "#([0-9]+)", 16 | 17 | "customIssues": [ 18 | { "name": "Features", "pattern": "#feature" }, 19 | { "name": "Bugs", "pattern": "#bug" } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /changelog.mustache: -------------------------------------------------------------------------------- 1 | # Git Changelog Bitbucket plugin changelog 2 | 3 | Changelog of Git Changelog Bitbucket plugin. 4 | 5 | {{#tags}} 6 | ## {{name}} 7 | {{#issues}} 8 | {{#hasIssue}} 9 | {{#hasLink}} 10 | ### {{name}} [{{issue}}]({{link}}) {{title}} 11 | {{/hasLink}} 12 | {{^hasLink}} 13 | ### {{name}} {{issue}} {{title}} 14 | {{/hasLink}} 15 | {{/hasIssue}} 16 | {{^hasIssue}} 17 | ### {{name}} 18 | {{/hasIssue}} 19 | 20 | {{#commits}} 21 | **{{{messageTitle}}}** 22 | 23 | {{#messageBodyItems}} 24 | * {{.}} 25 | {{/messageBodyItems}} 26 | 27 | [{{hash}}](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/{{hash}}) {{authorName}} *{{commitTime}}* 28 | 29 | {{/commits}} 30 | 31 | {{/issues}} 32 | {{/tags}} 33 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/settings/ValidationException.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.settings; 2 | 3 | public class ValidationException extends Exception { 4 | private static final long serialVersionUID = 2203598567281456784L; 5 | private final String error; 6 | private final String field; 7 | 8 | public ValidationException() { 9 | this.error = null; 10 | this.field = null; 11 | } 12 | 13 | public ValidationException(String field, String error) { 14 | this.error = error; 15 | this.field = field; 16 | } 17 | 18 | public String getError() { 19 | return error; 20 | } 21 | 22 | public String getField() { 23 | return field; 24 | } 25 | 26 | @Override 27 | public String getMessage() { 28 | return field + "=" + error; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/presentation/dto/ChangelogDTO.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.presentation.dto; 2 | 3 | import static com.google.common.base.Optional.fromNullable; 4 | 5 | import java.util.List; 6 | 7 | import com.google.common.base.Optional; 8 | 9 | public class ChangelogDTO { 10 | private final List references; 11 | private final String changelog; 12 | 13 | public ChangelogDTO(String changelog, List references) { 14 | this.references = references; 15 | this.changelog = changelog; 16 | } 17 | 18 | public ChangelogDTO(List references) { 19 | this.references = references; 20 | this.changelog = null; 21 | } 22 | 23 | public List getReferences() { 24 | return references; 25 | } 26 | 27 | public Optional getChangelog() { 28 | return fromNullable(changelog); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/settings/AdminFormValues.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.settings; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Map; 5 | 6 | import javax.xml.bind.annotation.XmlAccessType; 7 | import javax.xml.bind.annotation.XmlAccessorType; 8 | import javax.xml.bind.annotation.XmlRootElement; 9 | 10 | @XmlRootElement 11 | @XmlAccessorType(XmlAccessType.FIELD) 12 | public final class AdminFormValues extends ArrayList> { 13 | private static final long serialVersionUID = 9084184120202816120L; 14 | public static final String NAME = "name"; 15 | public static final String VALUE = "value"; 16 | 17 | public enum FIELDS { 18 | dateFormat, // 19 | timeZone, // 20 | ignoreCommitsIfMessageMatches, // 21 | untaggedName, // 22 | noIssueName, // 23 | template, // 24 | lookupJiraTitles 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/resources/static/changelog_html.mustache: -------------------------------------------------------------------------------- 1 |

{{projectName}} changelog

2 | 3 |

4 | Changelog of {{projectName}}. 5 |

6 | 7 | {{#tags}} 8 |

{{name}}

9 | {{#issues}} 10 | {{#hasIssue}} 11 | {{#hasLink}} 12 |

{{name}} {{issue}} {{title}}

13 | {{/hasLink}} 14 | {{^hasLink}} 15 |

{{name}} {{issue}} {{title}}

16 | {{/hasLink}} 17 | {{/hasIssue}} 18 | {{^hasIssue}} 19 |

{{name}}

20 | {{/hasIssue}} 21 | 22 | 23 | {{#commits}} 24 | {{hash}} {{authorName}} {{commitTime}} 25 |

{{{messageTitle}}}

26 |
    27 | {{#messageBodyItems}} 28 |
  • {{.}}
  • 29 | {{/messageBodyItems}} 30 |
31 | 32 | 33 | {{/commits}} 34 | 35 | {{/issues}} 36 | {{/tags}} 37 | -------------------------------------------------------------------------------- /src/main/resources/static/admin/admin.css: -------------------------------------------------------------------------------- 1 | .config-area { 2 | border: 1px; 3 | border-color: black; 4 | border-style: dotted; 5 | width: 550px; 6 | padding: 5px 15px; 7 | } 8 | 9 | fieldset { 10 | border: 1px; 11 | padding: 5px 15px; 12 | } 13 | 14 | legend { 15 | font-weight: bold; 16 | font-size: 20px; 17 | } 18 | 19 | .left { 20 | float: left; 21 | } 22 | 23 | .right { 24 | float: right; 25 | } 26 | 27 | .error { 28 | font-weight: bold; 29 | color: red; 30 | } 31 | 32 | input[type="text"], 33 | input[type="password"] { 34 | width: 100%; 35 | } 36 | 37 | .prnfb > form { 38 | margin: 10px 0 0 0; 39 | } 40 | 41 | .prnfb-template { 42 | display:none; 43 | } 44 | 45 | .visibleif { 46 | display:none; 47 | } 48 | 49 | th { 50 | text-align: left; 51 | } 52 | 53 | td > input[type="text"] { 54 | width: 90%; 55 | margin: 0 10% 0 0; 56 | float:left 57 | } 58 | 59 | .expandable .content { 60 | display: none; 61 | } 62 | 63 | .expandable.expanded .content { 64 | display: inherit; 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/se/bjurr/changelog/bitbucket/settings/SettingsStorageTest.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.settings; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.junit.Assert.assertNotNull; 5 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS.timeZone; 6 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.fromJson; 7 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.getValidatedSettings; 8 | 9 | import java.io.IOException; 10 | 11 | import org.junit.Test; 12 | 13 | public class SettingsStorageTest { 14 | 15 | @Test 16 | public void testThatDefaultSettingsAreUsedWhenNoPreviousConfig() throws IOException, ValidationException { 17 | AdminFormValues adminFormValues = fromJson(null); 18 | assertNotNull("timezone", SettingsStorage.getValue(adminFormValues, timeZone)); 19 | } 20 | 21 | @Test 22 | public void testThatDefaultSettingsAreValid() throws IOException, ValidationException { 23 | AdminFormValues adminFormValues = fromJson(null); 24 | assertThat(getValidatedSettings(adminFormValues).getTemplate())// 25 | .isNotNull(); 26 | assertThat(getValidatedSettings(adminFormValues).getLookupJiraTitles())// 27 | .as("This may be very time consuming!")// 28 | .isFalse(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/se/bjurr/changelog/bitbucket/application/ChangelogRepositoryServiceTest.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.application; 2 | 3 | import static com.google.common.collect.Lists.newArrayList; 4 | import static com.google.common.collect.Sets.newHashSet; 5 | import static org.junit.Assert.assertEquals; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.mockito.Mock; 10 | 11 | import com.atlassian.bitbucket.repository.RepositoryService; 12 | import com.atlassian.bitbucket.server.ApplicationPropertiesService; 13 | 14 | public class ChangelogRepositoryServiceTest { 15 | 16 | @Mock 17 | private ApplicationPropertiesService applicationPropertiesService; 18 | @Mock 19 | private RepositoryService repositoryService; 20 | private ChangelogRepositoryService changelogRepositoryService; 21 | 22 | @Before 23 | public void before() { 24 | this.changelogRepositoryService = new ChangelogRepositoryService(applicationPropertiesService, repositoryService); 25 | } 26 | 27 | @Test 28 | public void testThatReferencesAreFiltered() { 29 | assertEquals(// 30 | newArrayList(// 31 | "a", // 32 | "b", // 33 | "refs/c"), // 34 | changelogRepositoryService.transformReferencesToSimplerFormat(newHashSet(// 35 | "refs/heads/a",// 36 | "refs/tags/b",// 37 | "refs/c"))); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/se/bjurr/changelog/bitbucket/presentation/RepositoryServletTest.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.presentation; 2 | 3 | import static org.mockito.Mockito.mock; 4 | import static org.mockito.Mockito.when; 5 | import static org.mockito.MockitoAnnotations.initMocks; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | import org.mockito.Mock; 13 | 14 | import com.atlassian.bitbucket.repository.Repository; 15 | import com.atlassian.bitbucket.repository.RepositoryService; 16 | import com.atlassian.templaterenderer.TemplateRenderer; 17 | 18 | public class RepositoryServletTest { 19 | 20 | @Mock 21 | private TemplateRenderer renderer; 22 | @Mock 23 | private RepositoryService repositoryService; 24 | private RepositoryServlet repositoryServlet; 25 | 26 | @Before 27 | public void before() { 28 | initMocks(this); 29 | this.repositoryServlet = new RepositoryServlet(renderer, repositoryService); 30 | } 31 | 32 | @Test 33 | public void testThatProjectAndRepositoryIsRetrievedFromPathInURL() throws Exception { 34 | HttpServletRequest req = mock(HttpServletRequest.class); 35 | HttpServletResponse resp = mock(HttpServletResponse.class); 36 | Repository repository = mock(Repository.class); 37 | 38 | when(req.getPathInfo()) // 39 | .thenReturn("/some/path/here/project/repo"); 40 | when(repositoryService.getBySlug("project", "repo")) // 41 | .thenReturn(repository); 42 | 43 | repositoryServlet.doGet(req, resp); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/resources/static/admin/admin.js: -------------------------------------------------------------------------------- 1 | (function ($) { 2 | 'use strict'; 3 | var config_resource = AJS.contextPath() + "/rest/changelog/1.0/config"; 4 | $(document).ready(function() { 5 | $('input[name="save"]').click(function(e) { 6 | var $form = $(this).closest('form'); 7 | $(".post",$form).html("Saving..."); 8 | $.ajax({ 9 | url: config_resource, 10 | dataType: "json", 11 | type: "POST", 12 | contentType: "application/json", 13 | data: JSON.stringify($form.serializeArray(), null, 2), 14 | processData: false, 15 | error: function(xhr, data, error) { 16 | $(".error."+xhr.responseJSON.field,$form).html(xhr.responseJSON.error); 17 | if (xhr.responseJSON.field) { 18 | $(".post",$form).html("There were errors, form not saved!"); 19 | } else { 20 | $(".post",$form).html(xhr.responseText); 21 | } 22 | }, 23 | success: function(data, text, xhr) { 24 | $(".post",$form).html(''); 25 | getAll(); 26 | } 27 | }); 28 | }); 29 | 30 | function getAll() { 31 | $.ajax({ 32 | url: config_resource, 33 | dataType: "json" 34 | }).done(function(config) { 35 | $.each(config, function(fieldIndex,field_map) { 36 | var safe_value = field_map.value.replace(/[^a-zA-Z\_]/g,''); 37 | $('input[type="text"][name="'+field_map.name+'"]').attr('value', field_map.value); 38 | $('textarea[name="'+field_map.name+'"]').text(field_map.value); 39 | $('input[type="hidden"][name="'+field_map.name+'"]').attr('value', field_map.value); 40 | $('input[type="checkbox"][name="'+field_map.name+'"][value="'+safe_value+'"]').attr('checked','checked'); 41 | }); 42 | }); 43 | } 44 | 45 | getAll(); 46 | }); 47 | })(AJS.$ || jQuery); -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/presentation/RepositoryServlet.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.presentation; 2 | 3 | import static com.google.common.base.Preconditions.checkNotNull; 4 | import static com.google.common.collect.ImmutableMap.of; 5 | 6 | import java.io.IOException; 7 | 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.atlassian.bitbucket.repository.Repository; 14 | import com.atlassian.bitbucket.repository.RepositoryService; 15 | import com.atlassian.templaterenderer.TemplateRenderer; 16 | 17 | public class RepositoryServlet extends HttpServlet { 18 | private final TemplateRenderer renderer; 19 | private final RepositoryService repositoryService; 20 | 21 | private static final long serialVersionUID = 8180468320832783844L; 22 | 23 | public RepositoryServlet(TemplateRenderer renderer, RepositoryService repositoryService) { 24 | this.renderer = renderer; 25 | this.repositoryService = repositoryService; 26 | } 27 | 28 | @Override 29 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 30 | String pathInfo = req.getPathInfo(); 31 | String[] components = pathInfo.split("/"); 32 | String project = components[components.length - 2]; 33 | String repoSlug = components[components.length - 1]; 34 | final Repository repository = checkNotNull(repositoryService.getBySlug(project, repoSlug), // 35 | "Did not find " + project + " " + repoSlug); 36 | 37 | resp.setContentType("text/html;charset=UTF-8"); 38 | renderer.render( // 39 | "static/repository/repository.vm", // 40 | of( // 41 | "repository", repository // 42 | ), // 43 | resp.getWriter()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/resources/static/repository/repository.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | $repository.slug/Changelog 8 | $webResourceManager.requireResource("se.bjurr.changelog.git-changelog-for-bitbucket:repository-resources") 9 | $webResourceManager.requireResource("com.atlassian.auiplugin:aui-dropdown2") 10 | 11 | 12 |
13 |
14 |
15 |

Changelog

16 |
17 | 18 |
19 | 20 | 21 | 22 | From branch 23 |
24 | 27 |
28 | 29 | To branch 30 |
31 | 34 |
35 | 36 | 37 | 38 |

39 |
40 | 41 |
42 |
43 |
44 |
45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /src/test/java/se/bjurr/changelog/bitbucket/presentation/ConfigResourceTest.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.presentation; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.mockito.Mockito.mock; 5 | import static org.mockito.Mockito.when; 6 | import static org.mockito.MockitoAnnotations.initMocks; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.ws.rs.core.Response; 10 | 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.mockito.Mock; 14 | 15 | import se.bjurr.changelog.bitbucket.settings.AdminFormValues; 16 | 17 | import com.atlassian.bitbucket.user.SecurityService; 18 | import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; 19 | import com.atlassian.sal.api.transaction.TransactionTemplate; 20 | import com.atlassian.sal.api.user.UserKey; 21 | import com.atlassian.sal.api.user.UserManager; 22 | import com.atlassian.sal.api.user.UserProfile; 23 | 24 | public class ConfigResourceTest { 25 | 26 | @Mock 27 | private UserManager userManager; 28 | @Mock 29 | private PluginSettingsFactory pluginSettingsFactory; 30 | @Mock 31 | private TransactionTemplate transactionTemplate; 32 | @Mock 33 | private SecurityService securityService; 34 | private ConfigResource configResource; 35 | 36 | @Before 37 | public void before() { 38 | initMocks(this); 39 | configResource = new ConfigResource(userManager, pluginSettingsFactory, transactionTemplate, securityService); 40 | } 41 | 42 | @Test 43 | public void testThatUserMustBeAdministratorToAdministrate() throws Exception { 44 | UserProfile profile = mock(UserProfile.class); 45 | when(profile.getUserKey()) // 46 | .thenReturn(new UserKey("iserKey")); 47 | when(userManager.getRemoteUser()) // 48 | .thenReturn(profile); 49 | when(userManager.isAdmin(profile.getUserKey())) // 50 | .thenReturn(false); 51 | AdminFormValues adminFormValues = new AdminFormValues(); 52 | HttpServletRequest request = mock(HttpServletRequest.class); 53 | Response response = configResource.post(adminFormValues, request); 54 | assertEquals(401, response.getStatus()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/settings/ChangelogSettingsBuilder.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.settings; 2 | 3 | public class ChangelogSettingsBuilder { 4 | private String dateFormat; 5 | private String timeZone; 6 | private String template; 7 | private String ignoreCommitsIfMessageMatches; 8 | private String noIssueName; 9 | private String untaggedName; 10 | private boolean lookupJiraTitles; 11 | 12 | private ChangelogSettingsBuilder() { 13 | } 14 | 15 | public static ChangelogSettingsBuilder changelogSettingsBuilder() { 16 | return new ChangelogSettingsBuilder(); 17 | } 18 | 19 | public ChangelogSettings build() throws ValidationException { 20 | return new ChangelogSettings(this); 21 | } 22 | 23 | public String getDateFormat() { 24 | return dateFormat; 25 | } 26 | 27 | public ChangelogSettingsBuilder withDateFormat(String dateFormat) { 28 | this.dateFormat = dateFormat; 29 | return this; 30 | } 31 | 32 | public String getTimeZone() { 33 | return timeZone; 34 | } 35 | 36 | public ChangelogSettingsBuilder withTimeZone(String timeZone) { 37 | this.timeZone = timeZone; 38 | return this; 39 | } 40 | 41 | public ChangelogSettingsBuilder withIgnoreCommitsIfMessageMatches(String ignoreCommitsIfMessageMatches) { 42 | this.ignoreCommitsIfMessageMatches = ignoreCommitsIfMessageMatches; 43 | return this; 44 | } 45 | 46 | public String getIgnoreCommitsIfMessageMatches() { 47 | return ignoreCommitsIfMessageMatches; 48 | } 49 | 50 | public ChangelogSettingsBuilder withUntaggedName(String untaggedName) { 51 | this.untaggedName = untaggedName; 52 | return this; 53 | } 54 | 55 | public String getNoIssueName() { 56 | return noIssueName; 57 | } 58 | 59 | public String getUntaggedName() { 60 | return untaggedName; 61 | } 62 | 63 | public ChangelogSettingsBuilder withNoIssueName(String noIssueName) { 64 | this.noIssueName = noIssueName; 65 | return this; 66 | } 67 | 68 | public String getTemplate() { 69 | return template; 70 | } 71 | 72 | public ChangelogSettingsBuilder withTemplate(String template) { 73 | this.template = template; 74 | return this; 75 | } 76 | 77 | public boolean getLookupJiraTitles() { 78 | return lookupJiraTitles; 79 | } 80 | 81 | public ChangelogSettingsBuilder withLookupJiraTitles(boolean lookupJiraTitles) { 82 | this.lookupJiraTitles = lookupJiraTitles; 83 | return this; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/settings/ChangelogSettings.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.settings; 2 | 3 | import static com.google.common.base.Strings.isNullOrEmpty; 4 | 5 | import java.util.regex.Pattern; 6 | 7 | public class ChangelogSettings { 8 | private final String dateFormat; 9 | private final String timeZone; 10 | private final String template; 11 | private final String ignoreCommitsIfMessageMatches; 12 | private final String noIssueName; 13 | private final String untaggedName; 14 | private final boolean lookupJiraTitles; 15 | 16 | public ChangelogSettings(ChangelogSettingsBuilder builder) throws ValidationException { 17 | this.dateFormat = checkNotNullOrEmpty(builder.getDateFormat(), "dateFormat"); 18 | this.timeZone = checkNotNullOrEmpty(builder.getTimeZone(), "timeZone"); 19 | this.template = checkNotNullOrEmpty(builder.getTemplate(), "template"); 20 | this.ignoreCommitsIfMessageMatches = checkIsRegexp(builder.getIgnoreCommitsIfMessageMatches(), 21 | "ignoreCommitsIfMessageMatches"); 22 | this.noIssueName = checkNotNullOrEmpty(builder.getNoIssueName(), "noIssueName"); 23 | this.untaggedName = checkNotNullOrEmpty(builder.getUntaggedName(), "untaggedName"); 24 | this.lookupJiraTitles = builder.getLookupJiraTitles(); 25 | } 26 | 27 | private String checkIsRegexp(String value, String field) throws ValidationException { 28 | checkNotNullOrEmpty(value, field); 29 | try { 30 | Pattern.compile(value); 31 | } catch (Exception e) { 32 | throw new ValidationException(field, value + " is not a valid regexp! " + e.getMessage()); 33 | } 34 | return value; 35 | } 36 | 37 | private String checkNotNullOrEmpty(String value, String field) throws ValidationException { 38 | if (isNullOrEmpty(value)) { 39 | throw new ValidationException(field, field + " cannot be empy!"); 40 | } 41 | return value; 42 | } 43 | 44 | public String getDateFormat() { 45 | return dateFormat; 46 | } 47 | 48 | public String getIgnoreCommitsIfMessageMatches() { 49 | return ignoreCommitsIfMessageMatches; 50 | } 51 | 52 | public String getNoIssueName() { 53 | return noIssueName; 54 | } 55 | 56 | public String getTemplate() { 57 | return template; 58 | } 59 | 60 | public String getTimeZone() { 61 | return timeZone; 62 | } 63 | 64 | public String getUntaggedName() { 65 | return untaggedName; 66 | } 67 | 68 | public boolean getLookupJiraTitles() { 69 | return lookupJiraTitles; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/presentation/AdminServlet.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.presentation; 2 | 3 | import static com.google.common.base.Throwables.propagate; 4 | import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; 5 | import static se.bjurr.changelog.bitbucket.presentation.ConfigResource.isAdminAllowed; 6 | 7 | import java.io.IOException; 8 | import java.net.URI; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.http.HttpServlet; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | 15 | import com.atlassian.bitbucket.user.SecurityService; 16 | import com.atlassian.sal.api.auth.LoginUriProvider; 17 | import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; 18 | import com.atlassian.sal.api.user.UserManager; 19 | import com.atlassian.sal.api.user.UserProfile; 20 | import com.atlassian.templaterenderer.TemplateRenderer; 21 | 22 | public class AdminServlet extends HttpServlet { 23 | private static final long serialVersionUID = 3846987953228399693L; 24 | private final LoginUriProvider loginUriProvider; 25 | private final TemplateRenderer renderer; 26 | private final UserManager userManager; 27 | private final SecurityService securityService; 28 | private final PluginSettingsFactory pluginSettingsFactory; 29 | 30 | public AdminServlet(UserManager userManager, LoginUriProvider loginUriProvider, TemplateRenderer renderer, 31 | SecurityService securityService, PluginSettingsFactory pluginSettingsFactory) { 32 | this.userManager = userManager; 33 | this.loginUriProvider = loginUriProvider; 34 | this.renderer = renderer; 35 | this.securityService = securityService; 36 | this.pluginSettingsFactory = pluginSettingsFactory; 37 | } 38 | 39 | @Override 40 | public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 41 | UserProfile user = userManager.getRemoteUser(request); 42 | if (user == null) { 43 | response.sendRedirect(loginUriProvider.getLoginUri(getUri(request)).toASCIIString()); 44 | return; 45 | } 46 | try { 47 | if (!isAdminAllowed(userManager, request, securityService, pluginSettingsFactory)) { 48 | response.sendError(SC_FORBIDDEN, 49 | "You are not allowed to edit configuration " + loginUriProvider.getLoginUri(getUri(request)).toASCIIString()); 50 | return; 51 | } 52 | } catch (Exception e) { 53 | propagate(e); 54 | } 55 | response.setContentType("text/html;charset=utf-8"); 56 | renderer.render("static/admin/admin.vm", response.getWriter()); 57 | } 58 | 59 | private URI getUri(HttpServletRequest request) { 60 | StringBuffer builder = request.getRequestURL(); 61 | if (request.getQueryString() != null) { 62 | builder.append("?"); 63 | builder.append(request.getQueryString()); 64 | } 65 | return URI.create(builder.toString()); 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/application/ChangelogRepositoryService.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.application; 2 | 3 | import static com.google.common.base.Preconditions.checkNotNull; 4 | import static com.google.common.base.Predicates.equalTo; 5 | import static com.google.common.base.Predicates.not; 6 | import static com.google.common.collect.Iterables.filter; 7 | import static com.google.common.collect.Iterables.transform; 8 | import static com.google.common.collect.Lists.newArrayList; 9 | import static com.google.common.collect.Ordering.usingToString; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.util.List; 14 | import java.util.Map; 15 | import java.util.Set; 16 | 17 | import org.eclipse.jgit.api.Git; 18 | import org.eclipse.jgit.lib.Ref; 19 | import org.eclipse.jgit.storage.file.FileRepositoryBuilder; 20 | 21 | import com.atlassian.bitbucket.repository.Repository; 22 | import com.atlassian.bitbucket.repository.RepositoryService; 23 | import com.atlassian.bitbucket.server.ApplicationPropertiesService; 24 | import com.google.common.annotations.VisibleForTesting; 25 | 26 | public class ChangelogRepositoryService { 27 | private final ApplicationPropertiesService applicationPropertiesService; 28 | private final RepositoryService repositoryService; 29 | 30 | public ChangelogRepositoryService(ApplicationPropertiesService applicationPropertiesService, 31 | RepositoryService repositoryService) { 32 | this.applicationPropertiesService = applicationPropertiesService; 33 | this.repositoryService = repositoryService; 34 | } 35 | 36 | public File getRepositoryDir(final Repository repo) throws IOException { 37 | return applicationPropertiesService.getRepositoryDir(repo); 38 | } 39 | 40 | public List getReferences(File repositoryDir) throws IOException { 41 | org.eclipse.jgit.lib.Repository rep = new FileRepositoryBuilder()// 42 | .findGitDir(repositoryDir)// 43 | .readEnvironment().build(); 44 | try (Git jGit = new Git(rep)) { 45 | Map refsMap = jGit.getRepository().getAllRefs(); 46 | return transformReferencesToSimplerFormat(refsMap.keySet()); 47 | } 48 | } 49 | 50 | @VisibleForTesting 51 | List transformReferencesToSimplerFormat(Set allRefs) { 52 | Iterable refs = filter(allRefs, not(equalTo("HEAD"))); 53 | refs = transform(refs, input -> { 54 | if (input.startsWith("refs/heads/")) { 55 | input = input.substring("refs/heads/".length()); 56 | } 57 | if (input.startsWith("refs/tags/")) { 58 | input = input.substring("refs/tags/".length()); 59 | } 60 | return input; 61 | }); 62 | return usingToString() // 63 | .sortedCopy(newArrayList(refs)); 64 | } 65 | 66 | public Repository getRepository(String project, String repository) { 67 | final Repository repo = checkNotNull(repositoryService.getBySlug(project, repository), // 68 | "Did not find " + project + " " + repository); 69 | return repo; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/se/bjurr/changelog/bitbucket/presentation/AdminServletTest.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.presentation; 2 | 3 | import static org.mockito.Matchers.any; 4 | import static org.mockito.Matchers.anyInt; 5 | import static org.mockito.Matchers.anyString; 6 | import static org.mockito.Mockito.mock; 7 | import static org.mockito.Mockito.verify; 8 | import static org.mockito.Mockito.when; 9 | import static org.mockito.MockitoAnnotations.initMocks; 10 | 11 | import java.net.URI; 12 | import java.net.URISyntaxException; 13 | 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | 17 | import org.junit.Before; 18 | import org.junit.Test; 19 | import org.mockito.Mock; 20 | 21 | import com.atlassian.bitbucket.user.SecurityService; 22 | import com.atlassian.sal.api.auth.LoginUriProvider; 23 | import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; 24 | import com.atlassian.sal.api.user.UserKey; 25 | import com.atlassian.sal.api.user.UserManager; 26 | import com.atlassian.sal.api.user.UserProfile; 27 | import com.atlassian.templaterenderer.TemplateRenderer; 28 | 29 | public class AdminServletTest { 30 | @Mock 31 | private UserManager userManager; 32 | @Mock 33 | private LoginUriProvider loginUriProvider; 34 | @Mock 35 | private TemplateRenderer renderer; 36 | @Mock 37 | private SecurityService securityService; 38 | @Mock 39 | private PluginSettingsFactory pluginSettingsFactory; 40 | @Mock 41 | private HttpServletRequest request; 42 | @Mock 43 | private HttpServletResponse response; 44 | private AdminServlet adminServlet; 45 | 46 | @Before 47 | public void before() { 48 | initMocks(this); 49 | this.adminServlet = new AdminServlet(userManager, loginUriProvider, renderer, securityService, pluginSettingsFactory); 50 | } 51 | 52 | @Test 53 | public void testThatUserMustBeSignedInToAdministrate() throws Exception { 54 | mockLoginProvider(); 55 | 56 | adminServlet.doGet(request, response); 57 | verify(response).sendRedirect("redirectoToThis"); 58 | } 59 | 60 | @Test 61 | public void testThatUserMustBeAdministratorToAdministrate() throws Exception { 62 | mockLoginProvider(); 63 | UserProfile profile = mock(UserProfile.class); 64 | when(profile.getUserKey()) // 65 | .thenReturn(new UserKey("iserKey")); 66 | when(userManager.getRemoteUser(request)) // 67 | .thenReturn(profile); 68 | when(userManager.isAdmin(profile.getUserKey())) // 69 | .thenReturn(false); 70 | adminServlet.doGet(request, response); 71 | verify(response).sendError(anyInt(), anyString()); 72 | } 73 | 74 | private void mockLoginProvider() throws URISyntaxException { 75 | when(userManager.getRemoteUser(request)) // 76 | .thenReturn(null); 77 | when(request.getRequestURL()) // 78 | .thenReturn(new StringBuffer("http://loginurl/")); 79 | when(request.getQueryString()) // 80 | .thenReturn("querystring"); 81 | when(loginUriProvider.getLoginUri(any())).thenReturn(new URI("redirectoToThis")); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git Changelog Bitbucket Plugin [![Build Status](https://travis-ci.org/tomasbjerre/git-changelog-bitbucket-plugin.svg?branch=master)](https://travis-ci.org/tomasbjerre/git-changelog-bitbucket-plugin) 2 | 3 | Generates a changelog, or releasenotes, in Atlassian Bitbucket Server using [Git Changelog Lib](https://github.com/tomasbjerre/git-changelog-lib). 4 | 5 | Available in [Atlassian Marketplace](https://marketplace.atlassian.com/plugins/se.bjurr.changelog.git-changelog-for-bitbucket/server/overview). 6 | 7 | ## Changelog page 8 | The plugin adds a page on repository level where the user can select *from* and *to* branch to generate a changelog. 9 | 10 | There are some screenshots [here](https://github.com/tomasbjerre/git-changelog-lib/tree/screenshots/sandbox). 11 | 12 | ## REST API 13 | The plugin exposes the changelog as a REST API, available at */bitbucket/rest/changelog/1.0/* 14 | 15 | ``` 16 | /{project}/{repository} - First commit to master 17 | /{project}/{repository}/fromref/{fromRef}/toref/{toRef} 18 | /{project}/{repository}/fromref/{fromRef}/tocommit/{toCommit} 19 | /{project}/{repository}/fromcommit/{fromCommit}/toref/{toRef} 20 | /{project}/{repository}/fromcommit/{fromCommit}/tocommit/{toCommit} 21 | ``` 22 | 23 | If you have slash `/` in your branch names, they should be replaced with `_slash_`. Because Tomcat by default does not allow slashes encoded as [%2F](https://en.wikipedia.org/wiki/Directory_traversal_attack). 24 | 25 | ## Variables 26 | The changelog is available in the context of the template. These variables are documented in [Git Changelog Lib](https://github.com/tomasbjerre/git-changelog-lib). 27 | 28 | There are also some extended variables available in this Bitbucket plugin. 29 | 30 | * *repositoryName* Name of repository 31 | * *repositorySlug* Name of repository used in URL:s of Bitbucket 32 | * *projectName* Name of project 33 | * *projectKey* Name of project used in URL:s of Bitbucket 34 | * *jiraUrl* URL pointing to Jira, if you have one configured in Bitbucket 35 | * *bitbucketUrl* URL pointing at your Bitbucket server 36 | 37 | ## Developer instructions 38 | Prerequisites: 39 | 40 | * Atlas SDK [(installation instructions)](https://developer.atlassian.com/docs/getting-started/set-up-the-atlassian-plugin-sdk-and-build-a-project). 41 | * JDK 1.8 or newer 42 | 43 | Generate Eclipse project: 44 | ``` 45 | atlas-compile eclipse:eclipse 46 | ``` 47 | 48 | Package the plugin: 49 | ``` 50 | atlas-package 51 | ``` 52 | 53 | Run Bitbucket, with the plugin, on localhost: 54 | ``` 55 | export MAVEN_OPTS=-Dplugin.resource.directories=`pwd`/src/main/resources 56 | mvn bitbucket:run 57 | ``` 58 | 59 | You can also remote debug on port 5005 with: 60 | ``` 61 | mvn bitbucket:debug 62 | ``` 63 | 64 | Make a release [(detailed instructions)](https://developer.atlassian.com/docs/common-coding-tasks/development-cycle/packaging-and-releasing-your-plugin): 65 | 66 | * `mvn release:prepare release:perform` 67 | * Browse to GitHub page 68 | * Upload artifact 69 | * Write releasenotes 70 | * Go to Marketplace 71 | * Create a release 72 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/application/JiraClientService.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.application; 2 | 3 | import static com.atlassian.sal.api.net.Request.MethodType.GET; 4 | import static com.google.common.base.Optional.absent; 5 | import static com.google.common.base.Optional.of; 6 | import static java.util.logging.Level.SEVERE; 7 | 8 | import java.util.logging.Logger; 9 | 10 | import se.bjurr.gitchangelog.internal.integrations.jira.JiraClient; 11 | import se.bjurr.gitchangelog.internal.integrations.jira.JiraIssue; 12 | 13 | import com.atlassian.applinks.api.ApplicationLink; 14 | import com.atlassian.applinks.api.ApplicationLinkService; 15 | import com.atlassian.applinks.api.application.jira.JiraApplicationType; 16 | import com.atlassian.bitbucket.permission.Permission; 17 | import com.atlassian.bitbucket.user.SecurityService; 18 | import com.atlassian.bitbucket.util.Operation; 19 | import com.google.common.base.Optional; 20 | 21 | public class JiraClientService { 22 | private static Logger LOG = Logger.getLogger(JiraClientService.class.getSimpleName()); 23 | private static JiraClient NULL_JIRA_CLIENT = new JiraClient("") { 24 | @Override 25 | public Optional getIssue(String matched) { 26 | return absent(); 27 | } 28 | 29 | @Override 30 | public JiraClient withBasicCredentials(String username, String password) { 31 | return null; 32 | } 33 | }; 34 | private final ApplicationLinkService applicationLinkService; 35 | private final SecurityService securityService; 36 | 37 | public JiraClientService(ApplicationLinkService applicationLinkService, SecurityService securityService) { 38 | this.applicationLinkService = applicationLinkService; 39 | this.securityService = securityService; 40 | } 41 | 42 | public JiraClient getJiraClient(boolean lookupJiraTitles) { 43 | ApplicationLink primaryApplicationLink = this.applicationLinkService. // 44 | getPrimaryApplicationLink(JiraApplicationType.class); 45 | if (!lookupJiraTitles || primaryApplicationLink == null) { 46 | return NULL_JIRA_CLIENT; 47 | } 48 | String jiraUrlString = primaryApplicationLink.getRpcUrl().toString(); 49 | return new JiraClient(jiraUrlString) { 50 | @Override 51 | public Optional getIssue(String matched) { 52 | final String endpoint = getEndpoint(matched); 53 | try { 54 | String json = JiraClientService.this.securityService.withPermission(Permission.ADMIN, "Invoking Jira").call( 55 | new Operation() { 56 | @Override 57 | public String perform() throws Exception { 58 | return primaryApplicationLink // 59 | .createAuthenticatedRequestFactory() // 60 | .createRequest(GET, endpoint) // 61 | .execute(); 62 | } 63 | }); 64 | return of(toJiraIssue(matched, json)); 65 | } catch (Exception e) { 66 | LOG.log(SEVERE, "Could not read from:\n" + endpoint, e); 67 | } 68 | return absent(); 69 | } 70 | 71 | @Override 72 | public JiraClient withBasicCredentials(String username, String password) { 73 | return null; 74 | } 75 | }; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/resources/atlassian-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ${project.description} 4 | ${project.version} 5 | 6 | static/img/pluginIcon.png 7 | static/img/pluginLogo.png 8 | true 9 | /plugins/servlet/changelog/admin 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | com.atlassian.auiplugin:ajs 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | com.atlassian.auiplugin:ajs 32 | 33 | 34 | 35 | 36 | 37 | Provides REST resources for Changelog plugin. 38 | 39 | 40 | 41 | /changelog/admin 42 | 43 | 44 | 45 | /repository/* 46 | 47 | 48 | 49 | 50 | aui-icon icon-source 51 | /plugins/servlet/repository/${repository.project.key}/${repository.slug} 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/main/resources/static/admin/admin.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | Git Changelog for Bitbucket Admin 4 | 5 | $webResourceManager.requireResource("se.bjurr.changelog.git-changelog-for-bitbucket:admin-resources") 6 | 7 | 8 |
9 |
10 |
11 |
12 | Date 13 | 14 |
15 |
16 | Using Simple Date Format. 17 |
18 | 19 |
20 |
21 |
22 |
23 |
24 | Commits 25 |
26 | Ignore commits if regular expression matches message. 27 |
28 | 29 |
30 |
31 |
32 |
33 |
34 | Tags 35 |
36 | Commits that are not included in any tag will be included in this "virtual" tag. 37 |
38 | 39 |
40 |
41 |
42 |
43 |
44 | Issues 45 |
46 | Titles of Jiras can be included in the changelog. It may take a very long time to generate a changelog if alot of titles needs to be fetched. 47 |
48 | 49 |
50 | 51 |
52 | Commits do not contain any issue will be grouped in this "virtual" issue. 53 |
54 | 55 |
56 |
57 |
58 | 59 |
60 |
61 | Template 62 |
63 | You can use variables documented here. The context of this plugin has been extended with these variables. 64 |
    65 |
  • {{repositoryName}} Name of repository
  • 66 |
  • {{repositorySlug}} Name of repository used in URL:s of Bitbucket
  • 67 |
  • {{projectName}} Name of project
  • 68 |
  • {{projectKey}} Name of project used in URL:s of Bitbucket
  • 69 |
  • {{jiraUrl}} URL pointing to Jira, if you have one configured in Bitbucket
  • 70 |
  • {{bitbucketUrl}} URL pointing at your Bitbucket server
  • 71 |
72 |
73 | 74 |
75 |
76 |
77 |
78 | 79 | 80 |
81 |
82 |
83 |
84 | 85 | 86 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/presentation/ConfigResource.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.presentation; 2 | 3 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 4 | import static javax.ws.rs.core.Response.noContent; 5 | import static javax.ws.rs.core.Response.ok; 6 | import static javax.ws.rs.core.Response.status; 7 | import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 8 | import static javax.ws.rs.core.Response.Status.UNAUTHORIZED; 9 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.STORAGE_KEY; 10 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.fromJson; 11 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.getValidatedSettings; 12 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.toJson; 13 | 14 | import java.io.IOException; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.ws.rs.Consumes; 18 | import javax.ws.rs.GET; 19 | import javax.ws.rs.POST; 20 | import javax.ws.rs.Path; 21 | import javax.ws.rs.Produces; 22 | import javax.ws.rs.core.Context; 23 | import javax.ws.rs.core.Response; 24 | 25 | import se.bjurr.changelog.bitbucket.settings.AdminFormError; 26 | import se.bjurr.changelog.bitbucket.settings.AdminFormValues; 27 | import se.bjurr.changelog.bitbucket.settings.ValidationException; 28 | 29 | import com.atlassian.bitbucket.user.SecurityService; 30 | import com.atlassian.sal.api.pluginsettings.PluginSettings; 31 | import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; 32 | import com.atlassian.sal.api.transaction.TransactionTemplate; 33 | import com.atlassian.sal.api.user.UserManager; 34 | import com.atlassian.sal.api.user.UserProfile; 35 | 36 | @Path("/config") 37 | public class ConfigResource { 38 | 39 | private final PluginSettingsFactory pluginSettingsFactory; 40 | private final TransactionTemplate transactionTemplate; 41 | private final UserManager userManager; 42 | private final SecurityService securityService; 43 | 44 | public ConfigResource(UserManager userManager, PluginSettingsFactory pluginSettingsFactory, 45 | TransactionTemplate transactionTemplate, SecurityService securityService) { 46 | this.userManager = userManager; 47 | this.pluginSettingsFactory = pluginSettingsFactory; 48 | this.transactionTemplate = transactionTemplate; 49 | this.securityService = securityService; 50 | } 51 | 52 | /** 53 | * Get list of all notifications. 54 | */ 55 | @GET 56 | @Produces(APPLICATION_JSON) 57 | public Response get(@Context HttpServletRequest request) throws Exception { 58 | if (!isAdminAllowed(userManager, request, securityService, pluginSettingsFactory)) { 59 | return status(UNAUTHORIZED).build(); 60 | } 61 | 62 | return ok(getSettingsAsFormValues(transactionTemplate.execute(() -> pluginSettingsFactory.createGlobalSettings()))) 63 | .build(); 64 | } 65 | 66 | /** 67 | * Store a single notification setting. 68 | */ 69 | @POST 70 | @Consumes(APPLICATION_JSON) 71 | @Produces(APPLICATION_JSON) 72 | public Response post(final AdminFormValues adminFormValues, @Context HttpServletRequest request) throws Exception { 73 | if (!isAdminAllowed(userManager, request, securityService, pluginSettingsFactory)) { 74 | return status(UNAUTHORIZED).build(); 75 | } 76 | 77 | try { 78 | getValidatedSettings(adminFormValues); 79 | 80 | transactionTemplate.execute(() -> { 81 | pluginSettingsFactory.createGlobalSettings().put(STORAGE_KEY, toJson(adminFormValues)); 82 | return null; 83 | }); 84 | } catch (final ValidationException e) { 85 | return status(BAD_REQUEST).entity(new AdminFormError(e.getField(), e.getError())).build(); 86 | } 87 | 88 | return noContent().build(); 89 | } 90 | 91 | private AdminFormValues getSettingsAsFormValues(PluginSettings pluginSettings) throws IOException { 92 | return fromJson(pluginSettings.get(STORAGE_KEY)); 93 | } 94 | 95 | public static boolean isAdminAllowed(UserManager userManager, HttpServletRequest request, 96 | SecurityService securityService, final PluginSettingsFactory pluginSettingsFactory) throws Exception { 97 | final UserProfile user = userManager.getRemoteUser(request); 98 | if (user == null) { 99 | return false; 100 | } 101 | return userManager.isSystemAdmin(user.getUserKey()); 102 | } 103 | } -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/application/ChangelogLibService.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.application; 2 | 3 | import com.atlassian.applinks.api.ApplicationLink; 4 | import com.atlassian.applinks.api.ApplicationLinkService; 5 | import com.atlassian.applinks.api.application.bitbucket.BitbucketApplicationType; 6 | import com.atlassian.applinks.api.application.jira.JiraApplicationType; 7 | import com.atlassian.bitbucket.repository.Repository; 8 | import com.atlassian.bitbucket.server.ApplicationPropertiesService; 9 | import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; 10 | import com.google.common.collect.ImmutableMap; 11 | import com.google.common.collect.ImmutableMap.Builder; 12 | import se.bjurr.changelog.bitbucket.settings.ChangelogSettings; 13 | import se.bjurr.changelog.bitbucket.settings.ValidationException; 14 | import se.bjurr.gitchangelog.api.GitChangelogApi; 15 | import se.bjurr.gitchangelog.internal.integrations.jira.JiraClientFactory; 16 | 17 | import java.io.File; 18 | import java.io.IOException; 19 | import java.util.Map; 20 | 21 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.STORAGE_KEY; 22 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.fromJson; 23 | import static se.bjurr.changelog.bitbucket.settings.SettingsStorage.getValidatedSettings; 24 | import static se.bjurr.gitchangelog.api.GitChangelogApi.gitChangelogApiBuilder; 25 | import static se.bjurr.gitchangelog.api.GitChangelogApiConstants.DEFAULT_JIRA_ISSUE_PATTEN; 26 | 27 | public class ChangelogLibService { 28 | private static final String JIRA_URL = "jiraUrl"; 29 | private final PluginSettingsFactory pluginSettingsFactory; 30 | private final ApplicationLinkService applicationLinkService; 31 | private final ApplicationPropertiesService applicationPropertiesService; 32 | private final JiraClientService jiraClientService; 33 | 34 | public ChangelogLibService(PluginSettingsFactory pluginSettingsFactory, ApplicationLinkService applicationLinkService, 35 | ApplicationPropertiesService applicationPropertiesService, JiraClientService jiraClientService) { 36 | this.pluginSettingsFactory = pluginSettingsFactory; 37 | this.applicationLinkService = applicationLinkService; 38 | this.applicationPropertiesService = applicationPropertiesService; 39 | this.jiraClientService = jiraClientService; 40 | } 41 | 42 | public GitChangelogApi getGitChangelogApiBuilder(Repository repo) throws IOException, ValidationException { 43 | Builder extendedVariablesBuilder = ImmutableMap. builder() // 44 | .put("repositoryName", repo.getName()) // 45 | .put("repositorySlug", repo.getSlug()) // 46 | .put("projectName", repo.getProject().getName()) // 47 | .put("projectKey", repo.getProject().getKey()); 48 | ApplicationLink jiraApplicationLink = applicationLinkService.getPrimaryApplicationLink(JiraApplicationType.class); 49 | String jiraUrlString = null; 50 | if (jiraApplicationLink != null) { 51 | jiraUrlString = jiraApplicationLink.getDisplayUrl().toString(); 52 | extendedVariablesBuilder // 53 | .put(JIRA_URL, jiraUrlString); 54 | } 55 | if (applicationLinkService.getPrimaryApplicationLink(BitbucketApplicationType.class) != null) { 56 | extendedVariablesBuilder // 57 | .put("bitbucketUrl", applicationLinkService.getPrimaryApplicationLink(BitbucketApplicationType.class)); 58 | } 59 | ChangelogSettings settings = getValidatedSettings(fromJson(pluginSettingsFactory.createGlobalSettings().get( 60 | STORAGE_KEY))); 61 | File repositoryDir = applicationPropertiesService.getRepositoryDir(repo); 62 | Map extendedVariables = extendedVariablesBuilder.build(); 63 | JiraClientFactory.setJiraClient(jiraClientService.getJiraClient(settings.getLookupJiraTitles())); 64 | return gitChangelogApiBuilder() // 65 | .withFromRepo(repositoryDir.getAbsolutePath()) // 66 | .withExtendedVariables(extendedVariables) // 67 | .withDateFormat(settings.getDateFormat()) // 68 | .withJiraIssuePattern(DEFAULT_JIRA_ISSUE_PATTEN) // 69 | .withJiraServer(jiraUrlString) // 70 | .withIgnoreCommitsWithMessage(settings.getIgnoreCommitsIfMessageMatches()) // 71 | .withNoIssueName(settings.getNoIssueName()) // 72 | .withTemplateContent(settings.getTemplate()) // 73 | .withTimeZone(settings.getTimeZone()) // 74 | .withUntaggedName(settings.getUntaggedName()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/settings/SettingsStorage.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.settings; 2 | 3 | import static com.google.common.base.Charsets.UTF_8; 4 | import static com.google.common.collect.Iterables.find; 5 | import static com.google.common.collect.Iterables.tryFind; 6 | import static com.google.common.collect.Maps.newHashMap; 7 | import static com.google.common.io.Resources.getResource; 8 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.NAME; 9 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.VALUE; 10 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS.dateFormat; 11 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS.ignoreCommitsIfMessageMatches; 12 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS.lookupJiraTitles; 13 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS.noIssueName; 14 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS.template; 15 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS.timeZone; 16 | import static se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS.untaggedName; 17 | import static se.bjurr.changelog.bitbucket.settings.ChangelogSettingsBuilder.changelogSettingsBuilder; 18 | import static se.bjurr.gitchangelog.api.GitChangelogApiConstants.DEFAULT_DATEFORMAT; 19 | import static se.bjurr.gitchangelog.api.GitChangelogApiConstants.DEFAULT_IGNORE_COMMITS_REGEXP; 20 | import static se.bjurr.gitchangelog.api.GitChangelogApiConstants.DEFAULT_NO_ISSUE_NAME; 21 | import static se.bjurr.gitchangelog.api.GitChangelogApiConstants.DEFAULT_TIMEZONE; 22 | import static se.bjurr.gitchangelog.api.GitChangelogApiConstants.DEFAULT_UNTAGGED_NAME; 23 | 24 | import java.io.IOException; 25 | import java.util.Map; 26 | 27 | import se.bjurr.changelog.bitbucket.settings.AdminFormValues.FIELDS; 28 | 29 | import com.google.common.base.Predicate; 30 | import com.google.common.io.Resources; 31 | import com.google.gson.Gson; 32 | import com.google.gson.GsonBuilder; 33 | 34 | public class SettingsStorage { 35 | 36 | private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); 37 | 38 | public static final String STORAGE_KEY = "se.bjurr.changelog.bitbucket.admin_3"; 39 | 40 | public static ChangelogSettings getValidatedSettings(AdminFormValues adminFormValues) throws ValidationException { 41 | return changelogSettingsBuilder() // 42 | .withDateFormat(getValue(adminFormValues, dateFormat)) // 43 | .withTimeZone(getValue(adminFormValues, timeZone)) // 44 | .withIgnoreCommitsIfMessageMatches(getValue(adminFormValues, ignoreCommitsIfMessageMatches)) // 45 | .withUntaggedName(getValue(adminFormValues, untaggedName)) // 46 | .withNoIssueName(getValue(adminFormValues, noIssueName)) // 47 | .withTemplate(getValue(adminFormValues, template)) // 48 | .withLookupJiraTitles(hasValue(adminFormValues, lookupJiraTitles)) // 49 | .build(); 50 | } 51 | 52 | public static String getValue(AdminFormValues adminFormValues, FIELDS field) { 53 | return find(adminFormValues, withName(field.name())).get(VALUE); 54 | } 55 | 56 | public static boolean hasValue(AdminFormValues adminFormValues, FIELDS field) { 57 | return tryFind(adminFormValues, withName(field.name())).isPresent(); 58 | } 59 | 60 | private static Predicate> withName(final String name) { 61 | return input -> input.get(NAME).equals(name); 62 | } 63 | 64 | public static String toJson(AdminFormValues adminFormValues) { 65 | return gson.toJson(adminFormValues); 66 | } 67 | 68 | public static AdminFormValues fromJson(Object json) throws IOException { 69 | if (json == null) { 70 | AdminFormValues adminFormValues = new AdminFormValues(); 71 | adminFormValues.add(map(dateFormat, DEFAULT_DATEFORMAT)); 72 | adminFormValues.add(map(timeZone, DEFAULT_TIMEZONE)); 73 | adminFormValues.add(map(ignoreCommitsIfMessageMatches, DEFAULT_IGNORE_COMMITS_REGEXP)); 74 | adminFormValues.add(map(untaggedName, DEFAULT_UNTAGGED_NAME)); 75 | adminFormValues.add(map(noIssueName, DEFAULT_NO_ISSUE_NAME)); 76 | adminFormValues.add(map(template, Resources.toString(getResource("static/changelog_html.mustache"), UTF_8))); 77 | return adminFormValues; 78 | } else { 79 | return gson.fromJson((String) json, AdminFormValues.class); 80 | } 81 | } 82 | 83 | private static Map map(FIELDS field, String value) { 84 | Map map = newHashMap(); 85 | map.put(NAME, field.name()); 86 | map.put(VALUE, value); 87 | return map; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/resources/static/repository/repository.js: -------------------------------------------------------------------------------- 1 | (function ($) { 2 | 'use strict'; 3 | var config_resource = AJS.contextPath() + "/rest/changelog/1.0"; 4 | var changelogRaw; 5 | 6 | $(document).ready(function() { 7 | console.log("Using rest resource at: "+config_resource); 8 | 9 | function getParam(name){ 10 | var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.hash); 11 | if (results == null){ 12 | return null; 13 | } else { 14 | return results[1] || 0; 15 | } 16 | } 17 | 18 | function getTo() { 19 | return $("#changelog-to").val(); 20 | } 21 | 22 | function encodeForUrl(input) { 23 | return input.replace(/\//g,"_slash_"); 24 | } 25 | 26 | function getEndpoint(from,to) { 27 | var endpoint = config_resource; 28 | 29 | endpoint = endpoint + "/" + $("#changelog-project").val(); 30 | endpoint = endpoint + "/" + $("#changelog-repository").val(); 31 | 32 | if (!from || !to) { 33 | return endpoint; 34 | } 35 | 36 | if (from === '0000000000000000000000000000000000000000') { 37 | endpoint = endpoint + "/fromcommit/" + from; 38 | } else { 39 | endpoint = endpoint + "/fromref/" + encodeForUrl(from); 40 | } 41 | 42 | endpoint = endpoint + "/toref/" + encodeForUrl(to); 43 | 44 | return endpoint; 45 | } 46 | 47 | function updateChangelog(endpoint,from,to) { 48 | $('.git-changelog-spinner').spin(); 49 | $('.git-changelog-window').prop('disabled',true); 50 | $.ajax({ 51 | url: endpoint, 52 | dataType: "json", 53 | type: "GET", 54 | error: function(xhr, data, error) { 55 | console.log(xhr); 56 | console.log(data); 57 | console.log(error); 58 | $(".changelog").html(error); 59 | }, 60 | success: function(data, text, xhr) { 61 | changelogRaw = data.changelog; 62 | $("#changelog-content").html(changelogRaw); 63 | 64 | $("#changelog-from .branches").empty(); 65 | $("#changelog-from .branches").append('
  • First commit
  • '); 66 | for (var i = 0; i < data.references.length; i++) { 67 | $("#changelog-from .branches").append('
  • '+data.references[i]+'
  • '); 68 | } 69 | $("#changelog-from a").click(function() { 70 | setHash('from',$(this).data('branch')); 71 | }); 72 | 73 | $("#changelog-to .branches").empty(); 74 | for (var i = 0; i < data.references.length; i++) { 75 | $("#changelog-to .branches").append('
  • '+data.references[i]+'
  • '); 76 | } 77 | $("#changelog-to a").click(function() { 78 | setHash('to',$(this).data('branch')); 79 | }); 80 | }, 81 | error: function(data, text, xhr) { 82 | $('#git-changelog-plugin-status').html('Error :('); 83 | }, 84 | complete: function() { 85 | $('.git-changelog-spinner').spinStop(); 86 | $('.git-changelog-window').prop('disabled',false); 87 | } 88 | }); 89 | } 90 | 91 | function getChangelog(from,to) { 92 | setStatus(from,to); 93 | var endpoint = getEndpoint(from,to); 94 | updateChangelog(endpoint,from,to); 95 | } 96 | 97 | function setHash(withParam,withValue) { 98 | var hash = "?"; 99 | 100 | var from = getParam('from'); 101 | if (withParam == 'from') { 102 | hash += "from="+withValue; 103 | from = withValue; 104 | } else if (from) { 105 | hash += "&from="+from; 106 | } 107 | 108 | var to = getParam('to'); 109 | if (withParam == 'to') { 110 | hash += "&to="+withValue; 111 | to = withValue; 112 | } else if (to) { 113 | hash += "&to="+to; 114 | } 115 | 116 | window.location.hash = hash; 117 | getChangelog(from,to); 118 | } 119 | 120 | function setStatus(from,to) { 121 | var status = 'From '+from+' to '+to+'.'; 122 | if (!from && !to) { 123 | status = 'Select from and to branch.'; 124 | } else if (!from) { 125 | status = 'Select from branch.'; 126 | } else if (!to) { 127 | status = 'Select to branch.'; 128 | } 129 | $('#git-changelog-plugin-status').html(status); 130 | } 131 | 132 | if (window.location.hash.length > 0) { 133 | var from = getParam("from"); 134 | var to = getParam("to"); 135 | getChangelog(from,to); 136 | } else { 137 | getChangelog(null,null); 138 | } 139 | 140 | $('.git-changelog-window').click(function() { 141 | window.open().document.write(changelogRaw); 142 | }); 143 | }); 144 | })(AJS.$ || jQuery); -------------------------------------------------------------------------------- /src/main/java/se/bjurr/changelog/bitbucket/presentation/RestResource.java: -------------------------------------------------------------------------------- 1 | package se.bjurr.changelog.bitbucket.presentation; 2 | 3 | import static com.google.common.base.Charsets.UTF_8; 4 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 5 | import static javax.ws.rs.core.MediaType.TEXT_PLAIN; 6 | import static javax.ws.rs.core.Response.ok; 7 | import static javax.ws.rs.core.Response.status; 8 | 9 | import java.io.File; 10 | import java.net.URLDecoder; 11 | import java.util.List; 12 | 13 | import javax.ws.rs.GET; 14 | import javax.ws.rs.Path; 15 | import javax.ws.rs.PathParam; 16 | import javax.ws.rs.Produces; 17 | import javax.ws.rs.core.Response; 18 | 19 | import se.bjurr.changelog.bitbucket.application.ChangelogLibService; 20 | import se.bjurr.changelog.bitbucket.application.ChangelogRepositoryService; 21 | import se.bjurr.changelog.bitbucket.presentation.dto.ChangelogDTO; 22 | 23 | import com.atlassian.bitbucket.repository.Repository; 24 | import com.atlassian.sal.api.transaction.TransactionTemplate; 25 | import com.google.gson.Gson; 26 | import com.google.gson.GsonBuilder; 27 | 28 | @Path("/") 29 | public class RestResource { 30 | private static Gson gson = new GsonBuilder().setPrettyPrinting().create(); 31 | 32 | private final TransactionTemplate transactionTemplate; 33 | private final ChangelogLibService changelogLibService; 34 | private final ChangelogRepositoryService changelogRepositoryService; 35 | 36 | public RestResource(TransactionTemplate transactionTemplate, ChangelogLibService changelogLibService, 37 | ChangelogRepositoryService changelogRepositoryService) { 38 | this.transactionTemplate = transactionTemplate; 39 | this.changelogLibService = changelogLibService; 40 | this.changelogRepositoryService = changelogRepositoryService; 41 | } 42 | 43 | @GET 44 | @Produces(TEXT_PLAIN) 45 | @Path("/") 46 | public Response doGet() { 47 | return status(404) // 48 | .entity("" // 49 | + "/{project}/{repository} - First commit to master\n" // 50 | + "/{project}/{repository}/fromref/{fromRef}/toref/{toRef}\n" // 51 | + "/{project}/{repository}/fromref/{fromRef}/tocommit/{toCommit}\n" // 52 | + "/{project}/{repository}/fromcommit/{fromCommit}/toref/{toRef}\n" // 53 | + "/{project}/{repository}/fromcommit/{fromCommit}/tocommit/{toCommit}\n") // 54 | .build(); 55 | } 56 | 57 | @GET 58 | @Produces(APPLICATION_JSON) 59 | @Path("/{project}/{repository}") 60 | public Response getRefs(// 61 | @PathParam("project") String project, // 62 | @PathParam("repository") String repository) // 63 | throws Exception { 64 | 65 | final Repository repo = changelogRepositoryService.getRepository(project, repository); 66 | File repositoryDir = changelogRepositoryService.getRepositoryDir(repo); 67 | List references = changelogRepositoryService.getReferences(repositoryDir); 68 | ChangelogDTO changelogDto = new ChangelogDTO(references); 69 | 70 | return ok(transactionTemplate.execute(() -> gson.toJson(changelogDto))).build(); 71 | } 72 | 73 | @GET 74 | @Produces(APPLICATION_JSON) 75 | @Path("/{project}/{repository}/fromref/{fromRef}/toref/{toRef}") 76 | public Response getFromRefToRef(// 77 | @PathParam("project") String project, // 78 | @PathParam("repository") String repository,// 79 | @PathParam("fromRef") String fromRef,// 80 | @PathParam("toRef") String toRef) // 81 | throws Exception { 82 | 83 | final Repository repo = changelogRepositoryService.getRepository(project, repository); 84 | 85 | String changelog = changelogLibService.getGitChangelogApiBuilder(repo) // 86 | .withFromRef(decode(fromRef)) // 87 | .withToRef(decode(toRef)) // 88 | .render(); 89 | 90 | File repositoryDir = changelogRepositoryService.getRepositoryDir(repo); 91 | List references = changelogRepositoryService.getReferences(repositoryDir); 92 | ChangelogDTO changelogDto = new ChangelogDTO(changelog, references); 93 | 94 | return ok(transactionTemplate.execute(() -> gson.toJson(changelogDto))).build(); 95 | } 96 | 97 | @GET 98 | @Produces(APPLICATION_JSON) 99 | @Path("/{project}/{repository}/fromcommit/{fromCommit}/toref/{toRef}") 100 | public Response getFromCommitToRef(// 101 | @PathParam("project") String project, // 102 | @PathParam("repository") String repository,// 103 | @PathParam("fromCommit") String fromCommit,// 104 | @PathParam("toRef") String toRef) // 105 | throws Exception { 106 | 107 | final Repository repo = changelogRepositoryService.getRepository(project, repository); 108 | 109 | String changelog = changelogLibService.getGitChangelogApiBuilder(repo) // 110 | .withFromCommit(fromCommit) // 111 | .withToRef(decode(toRef)) // 112 | .render(); 113 | 114 | File repositoryDir = changelogRepositoryService.getRepositoryDir(repo); 115 | List references = changelogRepositoryService.getReferences(repositoryDir); 116 | ChangelogDTO changelogDto = new ChangelogDTO(changelog, references); 117 | 118 | return ok(transactionTemplate.execute(() -> gson.toJson(changelogDto))).build(); 119 | } 120 | 121 | @GET 122 | @Produces(APPLICATION_JSON) 123 | @Path("/{project}/{repository}/fromcommit/{fromCommit}/tocommit/{toCommit}") 124 | public Response getFromCommitToCommit(// 125 | @PathParam("project") String project, // 126 | @PathParam("repository") String repository,// 127 | @PathParam("fromCommit") String fromCommit, // 128 | @PathParam("toCommit") String toCommit) // 129 | throws Exception { 130 | 131 | final Repository repo = changelogRepositoryService.getRepository(project, repository); 132 | 133 | String changelog = changelogLibService.getGitChangelogApiBuilder(repo) // 134 | .withFromCommit(fromCommit) // 135 | .withToCommit(toCommit) // 136 | .render(); 137 | 138 | File repositoryDir = changelogRepositoryService.getRepositoryDir(repo); 139 | List references = changelogRepositoryService.getReferences(repositoryDir); 140 | ChangelogDTO changelogDto = new ChangelogDTO(changelog, references); 141 | 142 | return ok(transactionTemplate.execute(() -> gson.toJson(changelogDto))).build(); 143 | } 144 | 145 | @GET 146 | @Produces(APPLICATION_JSON) 147 | @Path("/{project}/{repository}/fromref/{fromRef}/tocommit/{toCommit}") 148 | public Response getFromRefToCommit(// 149 | @PathParam("project") String project, // 150 | @PathParam("repository") String repository,// 151 | @PathParam("fromRef") String fromRef, // 152 | @PathParam("toCommit") String toCommit) // 153 | throws Exception { 154 | 155 | final Repository repo = changelogRepositoryService.getRepository(project, repository); 156 | 157 | String changelog = changelogLibService.getGitChangelogApiBuilder(repo) // 158 | .withFromRef(decode(fromRef)) // 159 | .withToCommit(toCommit) // 160 | .render(); 161 | 162 | File repositoryDir = changelogRepositoryService.getRepositoryDir(repo); 163 | List references = changelogRepositoryService.getReferences(repositoryDir); 164 | ChangelogDTO changelogDto = new ChangelogDTO(changelog, references); 165 | 166 | return ok(transactionTemplate.execute(() -> gson.toJson(changelogDto))).build(); 167 | } 168 | 169 | private String decode(String ref) throws Exception { 170 | ref = ref.replaceAll("_slash_", "/"); 171 | return URLDecoder.decode(ref, UTF_8.name()); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | se.bjurr.changelog 6 | git-changelog-for-bitbucket 7 | 1.21-SNAPSHOT 8 | 9 | Tomas Bjerre 10 | http://bjurr.se/ 11 | 12 | git-changelog-for-bitbucket 13 | This is the Git Changelog for Atlassian Bitbucket. 14 | atlassian-plugin 15 | 16 | scm:git:git@github.com:tomasbjerre/git-changelog-bitbucket-plugin.git 17 | https://github.com/tomasbjerre/git-changelog-bitbucket-plugin 18 | HEAD 19 | 20 | 21 | 22 | local-repo 23 | LocalDir 24 | file://${project.basedir}/dist-maven 25 | 26 | 27 | 28 | 29 | atlassian-public 30 | https://maven.atlassian.com/repository/public 31 | 32 | true 33 | never 34 | warn 35 | 36 | 37 | true 38 | warn 39 | 40 | 41 | 42 | 43 | 44 | 45 | com.atlassian.bitbucket.server 46 | bitbucket-parent 47 | ${bitbucket.version} 48 | pom 49 | import 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.slf4j 57 | slf4j-api 58 | 1.7.12 59 | provided 60 | 61 | 62 | org.slf4j 63 | slf4j-simple 64 | 1.7.12 65 | provided 66 | 67 | 68 | org.slf4j 69 | jcl-over-slf4j 70 | 1.7.12 71 | provided 72 | 73 | 74 | org.slf4j 75 | jul-to-slf4j 76 | 1.7.12 77 | provided 78 | 79 | 80 | org.slf4j 81 | log4j-over-slf4j 82 | 1.7.12 83 | provided 84 | 85 | 86 | org.eclipse.jgit 87 | org.eclipse.jgit 88 | 4.1.0.201509280440-r 89 | 90 | 91 | se.bjurr.gitchangelog 92 | git-changelog-lib 93 | 1.88 94 | 95 | 96 | org.slf4j 97 | slf4j-api 98 | 99 | 100 | 101 | 102 | com.atlassian.applinks 103 | applinks-api 104 | provided 105 | 106 | 107 | com.atlassian.templaterenderer 108 | atlassian-template-renderer-api 109 | provided 110 | 111 | 112 | com.atlassian.bitbucket.server 113 | bitbucket-api 114 | provided 115 | 116 | 117 | com.atlassian.sal 118 | sal-api 119 | provided 120 | 121 | 122 | javax.servlet 123 | javax.servlet-api 124 | provided 125 | 126 | 127 | javax.ws.rs 128 | jsr311-api 129 | 1.1.1 130 | provided 131 | 132 | 133 | com.google.guava 134 | guava 135 | provided 136 | 137 | 138 | 139 | 140 | junit 141 | junit 142 | 4.12 143 | test 144 | 145 | 146 | org.mockito 147 | mockito-all 148 | 1.8.5 149 | test 150 | 151 | 152 | org.assertj 153 | assertj-core 154 | 3.3.0 155 | test 156 | 157 | 158 | com.sun.jersey 159 | jersey-client 160 | 1.19 161 | test 162 | 163 | 164 | 165 | 166 | 167 | com.atlassian.maven.plugins 168 | bitbucket-maven-plugin 169 | ${amps.version} 170 | true 171 | 172 | 173 | 174 | bitbucket 175 | bitbucket 176 | ${bitbucket.version} 177 | ${bitbucket.data.version} 178 | 179 | 180 | 181 | 182 | 183 | maven-compiler-plugin 184 | 185 | 1.8 186 | 1.8 187 | 188 | 189 | 190 | org.apache.maven.plugins 191 | maven-release-plugin 192 | 2.5 193 | 194 | 195 | org.apache.maven.plugins 196 | maven-surefire-plugin 197 | 2.17 198 | 199 | 200 | se.bjurr.gitchangelog 201 | git-changelog-maven-plugin 202 | 1.54 203 | 204 | 205 | GenerateGitChangelog 206 | generate-sources 207 | 208 | git-changelog 209 | 210 | 211 | -([^-]+?)$ 212 | https://api.github.com/repos/tomasbjerre/git-changelog-bitbucket-plugin 213 | ${GITHUB_OAUTH2TOKEN} 214 | #([0-9]*) 215 | CHANGELOG.md 216 | 217 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | src/main/resources 249 | true 250 | 251 | 252 | 253 | 254 | 5.13.1 255 | ${bitbucket.version} 256 | 2.0.0 257 | 6.3.6 258 | 259 | 260 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Changelog of Git Changelog Bitbucket plugin. 4 | 5 | ## 1.20 6 | ### GitHub [#25](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/25) JiraClientService uses DisplayUrl instead of RpcUrl 7 | fixes #25 JiraClientService uses DisplayUrl instead of RpcUrl 8 | 9 | [75c016e5c72c66f](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/75c016e5c72c66f) Aerni Mario, IT122 *2019-01-15 14:42:02* 10 | 11 | ### No issue 12 | Update lib to 1.88 13 | 14 | [aac4080681ab88b](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/aac4080681ab88b) Tomas Bjerre *2019-01-15 16:59:07* 15 | 16 | Building for 5.0 17 | 18 | [07eebd11b5824c9](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/07eebd11b5824c9) Tomas Bjerre *2017-05-14 07:01:04* 19 | 20 | ## 1.19 21 | ### No issue 22 | tag time added to tag model 23 | 24 | [4c963217c9e4e39](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/4c963217c9e4e39) Tomas Bjerre *2017-04-14 09:12:27* 25 | 26 | ## 1.18 27 | ### No issue 28 | Fix Jira labels 29 | 30 | [646c4f1018f9507](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/646c4f1018f9507) Tomas Bjerre *2017-03-20 18:19:28* 31 | 32 | ## 1.17 33 | ### No issue 34 | Git Changelog Lib 1.58 -> 1.64 35 | 36 | * Jira issueType and labels 37 | * GitHub labels 38 | * 10 seconds timeout to GitHub 39 | 40 | [58fddffa3b84725](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/58fddffa3b84725) Tomas Bjerre *2017-03-18 09:23:24* 41 | 42 | ## 1.16 43 | ### No issue 44 | Adding annotation to context of tag 45 | 46 | [c22e11970211d4c](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/c22e11970211d4c) Tomas Bjerre *2016-10-22 09:51:59* 47 | 48 | ## 1.15 49 | ### No issue 50 | Adding merge boolean to commits 51 | 52 | [2d9cdec045b9fa5](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/2d9cdec045b9fa5) Tomas Bjerre *2016-10-05 18:36:39* 53 | 54 | ## 1.14 55 | ### No issue 56 | Getting Jira issue name with admin priv 57 | 58 | [aca6b82b518b786](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/aca6b82b518b786) Tomas Bjerre *2016-08-19 18:52:23* 59 | 60 | ## 1.13 61 | ### No issue 62 | Lib 1.56 correcting link to Jira 63 | 64 | [0c66b38fc31cd7c](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/0c66b38fc31cd7c) Tomas Bjerre *2016-08-11 14:51:40* 65 | 66 | Fixed commit link in changelog_html.mustache 67 | 68 | Generated commit link was wrong due to wrong basepath 69 | Generated commit link was wrong due to usage of shortened commitID instead of full commitID 70 | 71 | [5aecedb4a3da302](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/5aecedb4a3da302) hoppfrosch *2016-08-11 05:09:49* 72 | 73 | doc 74 | 75 | [5e38331e92f1e0a](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/5e38331e92f1e0a) Tomas Bjerre *2016-08-10 14:08:52* 76 | 77 | ## 1.12 78 | ### GitHub [#21](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/21) Template: {{hash}} vs. {{hashFull}} 79 | Using lib 1.55, adding {{hashFull}} #21 80 | 81 | [86f901bbcf40937](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/86f901bbcf40937) Tomas Bjerre *2016-08-10 14:07:39* 82 | 83 | Using lib 1.55, adding {{hashFull}} #21 84 | 85 | [8482c11fe3262f0](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/8482c11fe3262f0) Tomas Bjerre *2016-08-10 14:07:07* 86 | 87 | ## 1.11 88 | ### GitHub [#20](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/20) Errors installing in 4.8.1 89 | Avoiding crash on startup #20 90 | 91 | [825a1a0f68ebde3](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/825a1a0f68ebde3) Tomas Bjerre *2016-07-30 09:12:17* 92 | 93 | ## 1.10 94 | ### No issue 95 | Lib 1.53 96 | 97 | [bae2642ddec0771](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/bae2642ddec0771) Tomas Bjerre *2016-06-26 18:36:52* 98 | 99 | ## 1.9 100 | ### No issue 101 | Ignoring trailing slash in JIRA URL 102 | 103 | [18f022c69c17707](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/18f022c69c17707) Tomas Bjerre *2016-05-20 19:34:08* 104 | 105 | ## 1.8 106 | ### No issue 107 | Using lib 1.45 108 | 109 | [f288eae0f98fd11](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/f288eae0f98fd11) Tomas Bjerre *2016-04-14 16:48:40* 110 | 111 | Updating debug info in README.md 112 | 113 | [657267ba42bd2df](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/657267ba42bd2df) Tomas Bjerre *2016-02-24 18:17:28* 114 | 115 | ## 1.7 116 | ### No issue 117 | Supplying commit in each issue mentioned in message 118 | 119 | [4d8795c65c72f21](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/4d8795c65c72f21) Tomas Bjerre *2016-02-20 08:36:21* 120 | 121 | ## 1.6 122 | ### GitHub [#12](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/12) Optionally lookup jira titles 123 | Using Bitbuckets Jira authenticated HTTP Client #12 #14 #15 124 | 125 | * Was not authenticating. 126 | * Also adding checkbox to optionally fetch titles. This solves #14 where the plugin most likely got stuck on waiting for Jira. 127 | 128 | [7daad7759006fc5](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/7daad7759006fc5) Tomas Bjerre *2016-02-19 21:24:34* 129 | 130 | ### GitHub [#14](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/14) Initial changelog 131 | Using Bitbuckets Jira authenticated HTTP Client #12 #14 #15 132 | 133 | * Was not authenticating. 134 | * Also adding checkbox to optionally fetch titles. This solves #14 where the plugin most likely got stuck on waiting for Jira. 135 | 136 | [7daad7759006fc5](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/7daad7759006fc5) Tomas Bjerre *2016-02-19 21:24:34* 137 | 138 | ### GitHub [#15](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/15) Bitbucket -> Jira: Http Error 401 139 | Using Bitbuckets Jira authenticated HTTP Client #12 #14 #15 140 | 141 | * Was not authenticating. 142 | * Also adding checkbox to optionally fetch titles. This solves #14 where the plugin most likely got stuck on waiting for Jira. 143 | 144 | [7daad7759006fc5](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/7daad7759006fc5) Tomas Bjerre *2016-02-19 21:24:34* 145 | 146 | ### No issue 147 | Updating CHANGELOG.md 148 | 149 | [9409b8336507de7](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/9409b8336507de7) Tomas Bjerre *2016-02-15 19:44:59* 150 | 151 | ## 1.5 152 | ### GitHub [#13](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/13) Error on creating changelog 153 | Lib 1.30, supporting multiple tags per commit #13 154 | 155 | * Also encoding slashes as \_slash\_ in REST-api. 156 | 157 | [528e021138be70f](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/528e021138be70f) Tomas Bjerre *2016-02-15 19:39:54* 158 | 159 | ### No issue 160 | Updating CHANGELOG.md 161 | 162 | [8681b7f916942f2](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/8681b7f916942f2) Tomas Bjerre *2016-02-14 19:19:01* 163 | 164 | ## 1.4 165 | ### GitHub [#1](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/1) Support Jira integration 166 | Linking Jira:s #1 167 | 168 | * Also Correcting reference listing on changelog page. 169 | 170 | [955f59691e177a6](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/955f59691e177a6) Tomas Bjerre *2016-02-14 19:16:24* 171 | 172 | ## 1.3 173 | ### GitHub [#6](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/6) Hangs for large repos 174 | Updating changelog only when user selects from, and to, branches #6 175 | 176 | [96335908f986c65](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/96335908f986c65) Tomas Bjerre *2016-02-14 06:32:06* 177 | 178 | ### No issue 179 | Adding button to open changelog in new window 180 | 181 | * And other GUI improvements. 182 | 183 | [4824da64acfcece](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/4824da64acfcece) Tomas Bjerre *2016-02-14 08:30:46* 184 | 185 | Updating CHANGELOG.md 186 | 187 | [f10e97e44d4476c](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/f10e97e44d4476c) Tomas Bjerre *2016-02-13 17:23:25* 188 | 189 | ## 1.2 190 | ### GitHub [#6](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/6) Hangs for large repos 191 | Significant performance improvements #6 192 | 193 | * Using lib 1.27. 194 | 195 | [d182238e306a860](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/d182238e306a860) Tomas Bjerre *2016-02-13 09:27:02* 196 | 197 | ### No issue 198 | Git changelog lib 1.25 199 | 200 | [b0dcca6b807048d](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/b0dcca6b807048d) Tomas Bjerre *2016-02-10 18:46:58* 201 | 202 | ## 1.1 203 | ### GitHub [#4](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/4) Refactor and add test cases 204 | Adding some test cases #4 205 | 206 | [61038babd877d50](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/61038babd877d50) Tomas Bjerre *2015-12-07 20:30:44* 207 | 208 | Creating services and moving stuff around #4 209 | 210 | [108f10560ac9028](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/108f10560ac9028) Tomas Bjerre *2015-12-07 19:36:13* 211 | 212 | ### GitHub [#5](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/issues/5) Wrong date of some commits 213 | Added variables: messageTitle, messageBody, messageItems #5 214 | 215 | [ed6d538323defa7](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/ed6d538323defa7) Tomas Bjerre *2016-02-09 19:46:20* 216 | 217 | ### No issue 218 | Using lib 1.23 219 | 220 | [5c56b2c9481a7fc](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/5c56b2c9481a7fc) Tomas Bjerre *2016-01-31 11:24:28* 221 | 222 | Correcting link to Marketplace 223 | 224 | [f3a7fb575b506c5](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/f3a7fb575b506c5) Tomas Bjerre *2015-12-15 05:37:35* 225 | 226 | Adding link to Atlassian Marketplace in readme 227 | 228 | [fdcc554d6532248](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/fdcc554d6532248) Tomas Bjerre *2015-12-06 17:06:54* 229 | 230 | Adding changelog 231 | 232 | [20318a3a986f4c5](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/20318a3a986f4c5) Tomas Bjerre *2015-12-06 08:03:26* 233 | 234 | ## 1.0 235 | ### No issue 236 | Admin GUI 237 | 238 | [7e1cbad42b5db5c](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/7e1cbad42b5db5c) Tomas Bjerre *2015-12-05 19:23:50* 239 | 240 | Refactored and added test 241 | 242 | [8a6e09c11ee4064](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/8a6e09c11ee4064) Tomas Bjerre *2015-12-05 15:22:01* 243 | 244 | Adding extended variables 245 | 246 | [5356c3b3531a221](https://github.com/tomasbjerre/git-changelog-bitbucket-plugin/commit/5356c3b3531a221) Tomas Bjerre *2015-12-05 15:07:45* 247 | 248 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------