1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.openjdk.skara.bots.notify; 24 25 import org.openjdk.skara.forge.HostedRepository; 26 import org.openjdk.skara.issuetracker.Issue; 27 import org.openjdk.skara.issuetracker.IssueProject; 28 import org.openjdk.skara.vcs.*; 29 import org.openjdk.skara.vcs.openjdk.*; 30 31 import java.util.List; 32 import java.util.logging.Logger; 33 34 public class IssueUpdater implements UpdateConsumer { 35 private final IssueProject issueProject; 36 private final Logger log = Logger.getLogger("org.openjdk.skara.bots.notify"); 37 38 IssueUpdater(IssueProject issueProject) { 39 this.issueProject = issueProject; 40 } 41 42 @Override 43 public void handleCommits(HostedRepository repository, List<Commit> commits, Branch branch) { 44 for (var commit : commits) { 45 var commitNotification = CommitFormatters.commitToTextBrief(repository, commit); 46 var commitMessage = CommitMessageParsers.v1.parse(commit); 47 for (var commitIssue : commitMessage.issues()) { 48 var issue = issueProject.issue(commitIssue.id()); 49 if (issue.isEmpty()) { 50 log.severe("Cannot update issue " + commitIssue.id() + " with commit " + commit.hash().abbreviate() 51 + " - issue not found in issue project"); 52 continue; 53 } 54 issue.get().addComment(commitNotification); 55 issue.get().setState(Issue.State.CLOSED); 56 } 57 } 58 } 59 60 @Override 61 public void handleOpenJDKTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotated) { 62 63 } 64 65 @Override 66 public void handleTagCommit(HostedRepository repository, Commit commit, Tag tag, Tag.Annotated annotation) { 67 68 } 69 70 @Override 71 public void handleNewBranch(HostedRepository repository, List<Commit> commits, Branch parent, Branch branch) { 72 73 } 74 }