Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright (c) 2013, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.pull.shared;
 
 
 import java.util.List;
A shared functionality regarding mergeable PRs, Github and Bugzilla.

Author(s):
Ivo Studensky
wangchao
 
 public class PullHelper {
     private static final Pattern BUILD_OUTCOME = Pattern.compile(
             "outcome was (\\*\\*)?+(SUCCESS|FAILURE|ABORTED)(\\*\\*)?+ using a merge of ([a-z0-9]+)".);
 
     public static final Pattern PENDING = Pattern.compile(".*Build.*merging.*has\\W+been\\W+triggered.*",
             . | .);
     public static final Pattern RUNNING = Pattern.compile(".*Build.*merging.*has\\W+been\\W+started.*",
             . | .);
     public static final Pattern FINISHED = Pattern.compile(".*Build.*merging.*has\\W+been\\W+finished.*",
             . | .);
     public static final Pattern MERGE = Pattern.compile(".*(re)?merge\\W+this\\W+please.*".
             | .);
     public static final Pattern FORCE_MERGE = Pattern.compile(".*force\\W+merge\\W+this.*".
             | .);
 
 //    private final Properties props;
 
     private final PullEvaluatorFacade evaluatorFacade;
 
     private final UserList adminList;
 
     // ------- Specific Helpers
     private final GithubHelper ghHelper;
     public GithubHelper getGHHelper(){
         return ;
     }
     private final BZHelper bzHelper;
     public BZHelper getBZHelper(){
         return ;
     }
 
     private final Properties props;
     public Properties getProperties(){
         return ;
     }
 
     public PullHelper(final String configurationFilePropertyfinal String configurationFileDefaultthrows Exception {
         try {
              = new GithubHelper(configurationFilePropertyconfigurationFileDefault);
              = new BZHelper(configurationFilePropertyconfigurationFileDefault);
 
              = Util.loadProperties(configurationFilePropertyconfigurationFileDefault);
 
             // initialize evaluators
              = new PullEvaluatorFacade(this);
 
              = UserList.loadUserList(Util.require("admin.list.file"));
 
         } catch (Exception e) {
             ..printf("Cannot initialize: %s\n"e);
             e.printStackTrace(.);
             throw e;
         }
     }
 
         return ;
    }

    
Checks the state of the given pull request from the pull-processor perspective.

Parameters:
pullRequest the pull request
Returns:
relevant state
    public ProcessorPullState checkPullRequestState(final PullRequest pullRequest) {
        ProcessorPullState result = .;
        try {
            final List<Commentcomments = .getComments(pullRequest);
            for (Comment comment : comments) {
                if (.getGithubLogin().equals(comment.getUser().getLogin())) {
                    if (.matcher(comment.getBody()).matches()) {
                        result = .;
                        continue;
                    }
                    if (.matcher(comment.getBody()).matches()) {
                        result = .;
                        continue;
                    }
                    if (.matcher(comment.getBody()).matches()) {
                        result = .;
                        continue;
                    }
                }
                if (.matcher(comment.getBody()).matches()) {
                    result = .;
                    continue;
                }
            }
            if (result == . || result == .) {
                // check other conditions, i.e. upstream pull request and bugzilla and jira...
                final PullEvaluator.Result mergeable = .isMergeable(pullRequest);
                if (!mergeable.isMergeable()) {
                    result = .;
                }
                if (result == . && !comments.isEmpty()) {
                    Comment lastComment = comments.get(comments.size() - 1);
                    if (.matcher(lastComment.getBody()).matches() && isAdminUser(lastComment.getUser().getLogin()))
                        result = .;
                }
            }
        } catch (IOException e) {
            ..printf("Cannot read comments of PR#%d due to %s\n"pullRequest.getNumber(), e);
            result = .;
        }
        return result;
    }
    public boolean isAdminUser(final String username) {
        return .has(username);
    }
    public boolean isMerged(final PullRequest pullRequest) {
        if (pullRequest == null) {
            return false;
        }
        if (!pullRequest.getState().equals("closed")) {
            return false;
        }
        try {
            if (.isMerged(pullRequest)) {
                return true;
            }
        } catch (IOException ignore) {
            ..printf("Cannot get Merged information of the pull request %d: %s.\n"pullRequest.getNumber(), ignore);
            ignore.printStackTrace(.);
        }
        try {
            final List<Commentcomments = .getComments(pullRequest);
            for (Comment comment : comments) {
                if (comment.getBody().toLowerCase().indexOf("merged") != -1) {
                    return true;
                }
            }
        } catch (IOException ignore) {
            ..printf("Cannot get comments of the pull request %d: %s.\n"pullRequest.getNumber(), ignore);
            ignore.printStackTrace(.);
        }
        return false;
    }
    public BuildResult checkBuildResult(PullRequest pullRequest) {
        BuildResult buildResult = .;
        List<Commentcomments;
        try {
            comments = .getComments(pullRequest);
        } catch (IOException e) {
            ..println("Error to get comments for pull request : " + pullRequest.getNumber());
            e.printStackTrace(.);
            return buildResult;
        }
        for (Comment comment : comments) {
            Matcher matcher = .matcher(comment.getBody());
            while (matcher.find()) {
                buildResult = BuildResult.valueOf(matcher.group(2));
            }
        }
        return buildResult;
    }
New to GrepCode? Check out our FAQ X