コード例 #1
0
 @Override
 public final void issueCreated(final GithubIssueResponse response, final Todo todo)
     throws IOException {
   final BufferedReader file = new BufferedReader(new FileReader(todo.getFile()));
   String line;
   String input = "";
   while ((line = file.readLine()) != null) {
     input += line + '\n';
   }
   file.close();
   final String[] lines = input.split("\\n");
   for (String current : lines) {
     if (current.replaceAll(" ", "").equals("title:" + response.getTitle().replaceAll(" ", ""))) {
       input =
           input.replace(
               current + "\n",
               current
                   + "\n"
                   + current
                       .replace("title: ", "id: ")
                       .replace(response.getTitle(), String.valueOf(response.getNumber()))
                   + "\n");
     }
   }
   FileOutputStream fileOut = new FileOutputStream(todo.getFile());
   fileOut.write(input.getBytes());
   fileOut.close();
 }
コード例 #2
0
  @Override
  public final void removeClosed(final List<Todo> todos, final Configurations conf)
      throws IOException, GithubException {
    List<GithubIssueResponse> issues = new GithubConnector().getIssues(conf);
    for (GithubIssueResponse issue : issues) {
      if (issue.getState().equals("closed")) {
        for (Todo todo : todos) {
          if (todo.getIssue().getId() != null) {
            if (todo.getIssue().getId().intValue() == issue.getNumber().intValue()) {
              Logger.getlog()
                  .info(
                      "Todo with issue id #"
                          + issue.getNumber()
                          + " is closed and will be deleted");
            }
            final BufferedReader file = new BufferedReader(new FileReader(todo.getFile()));
            String line;
            final StringBuilder input = new StringBuilder("");
            while ((line = file.readLine()) != null) {
              input.append(line).append('\n');
            }
            file.close();
            final Pattern patternComment =
                Pattern.compile(
                    "(/\\*([^*]|[\\r\\n]|"
                        + "(\\*+([^*/]|"
                        + "[\\r\\n])))*\\*+/)|"
                        + "(<!--([\\s\\S]*?)-->)|"
                        + "(=begin([\\s\\S]*?)=end)|"
                        + "(=pod([\\s\\S]*?)=cut)");
            final java.util.regex.Matcher matcher = patternComment.matcher(input.toString());
            while (matcher.find()) {
              if (matcher.group(0).replaceAll(" ", "").contains("id:" + issue.getNumber())) {

                final String output = input.toString().replace(matcher.group(0), "");
                FileOutputStream fileOut = new FileOutputStream(todo.getFile());
                fileOut.write(output.getBytes());
                fileOut.close();
                break;
              }
            }
          }
        }
      }
    }
  }