Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.sonyericsson.hudson.plugins.gerrit.trigger;
 
Turns "Change-ID: XXXX" into a hyperlink to Gerrit.

Author(s):
Kohsuke Kawaguchi
public class ChangeIdAnnotator extends ChangeLogAnnotator {
    @Override
    public void annotate(AbstractBuild<?, ?> buildEntry changeMarkupText text) {
        IGerritHudsonTriggerConfig config = PluginImpl.getInstance().getConfig();
        annotate(build.getProject(), textconfig);
    }

    
Annotates Gerrit change IDs in changelogs.

Parameters:
project The project
text The initial text
config The Gerrit trigger config
    public void annotate(AbstractProject<?, ?> projectMarkupText textIGerritHudsonTriggerConfig config) {
        for (SubText token : text.findTokens()) {
            if (!hasGerritTrigger(project)) {
                return// not configured with Gerrit
            }
            token.href(config.getGerritFrontEndUrl() + "r/" + token.getText());
        }
    }

    
Does this project have the Gerrit trigger configured?

Parameters:
project The project
Returns:
True if the gerrit trigger is configured.
    private boolean hasGerritTrigger(AbstractProject<?, ?> project) {
        for (Trigger t : project.getTriggers().values()) {
            if (t instanceof GerritTrigger) {
                return true;
            }
        }
        return false;
    }
    private static final Pattern CHANGE_ID = Pattern.compile("(?<=\\bChange-Id: )I[0-9a-fA-F]{40}\\b");
New to GrepCode? Check out our FAQ X