Skip to content

Commit

Permalink
SKARA-2370
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaosongzs committed Sep 10, 2024
1 parent c351061 commit 3c63f2b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ public boolean allowedInCommit() {
return true;
}

private static final String USER_INVALID_WARNING = "To use the `/backport` command, you need to be in the OpenJDK [census](https://openjdk.org/census)"
+ " and your GitHub account needs to be linked with your OpenJDK username"
+ " ([how to associate your GitHub account with your OpenJDK username]"
+ "(https://wiki.openjdk.org/display/skara#Skara-AssociatingyourGitHubaccountandyourOpenJDKusername)).";

private static final String INSUFFICIENT_ACCESS_WARNING = "The backport can not be created because you don't have access to the target repository.";

private static final int BRANCHES_LIMIT = 10;
Expand All @@ -82,7 +77,7 @@ public boolean allowedInCommit() {
public void handle(PullRequestBot bot, PullRequest pr, CensusInstance censusInstance, ScratchArea scratchArea, CommandInvocation command,
List<Comment> allComments, PrintWriter reply, List<String> labelsToAdd, List<String> labelsToRemove) {
if (censusInstance.contributor(command.user()).isEmpty()) {
reply.println(USER_INVALID_WARNING);
printInvalidUserWarning(bot, reply);
return;
}

Expand Down Expand Up @@ -241,7 +236,7 @@ private Branch getTargetBranch(String[] parts, int index, HostedRepository targe
public void handle(PullRequestBot bot, HostedCommit commit, LimitedCensusInstance censusInstance,
ScratchArea scratchArea, CommandInvocation command, List<Comment> allComments, PrintWriter reply) {
if (censusInstance.contributor(command.user()).isEmpty() && !command.user().equals(bot.repo().forge().currentUser())) {
reply.println(USER_INVALID_WARNING);
printInvalidUserWarning(bot, reply);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,7 +25,6 @@
import org.openjdk.skara.forge.HostedBranch;
import org.openjdk.skara.forge.HostedCommit;
import org.openjdk.skara.issuetracker.Comment;
import org.openjdk.skara.vcs.*;
import org.openjdk.skara.jcheck.JCheckConfiguration;

import java.io.PrintWriter;
Expand Down Expand Up @@ -73,10 +72,7 @@ public void handle(PullRequestBot bot, HostedCommit commit, LimitedCensusInstanc
return;
}
if (censusInstance.contributor(command.user()).isEmpty()) {
reply.println("To use the `/branch` command, you need to be in the OpenJDK [census](https://openjdk.org/census)"
+ " and your GitHub account needs to be linked with your OpenJDK username"
+ " ([how to associate your GitHub account with your OpenJDK username]"
+ "(https://wiki.openjdk.org/display/skara#Skara-AssociatingyourGitHubaccountandyourOpenJDKusername)).");
printInvalidUserWarning(bot, reply);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -59,4 +59,15 @@ default boolean allowedInCommit() {
default boolean allowedInPullRequest() {
return true;
}

default void printInvalidUserWarning(PullRequestBot bot, PrintWriter reply) {
if (bot.repo().forge().name().equals("GitHub")) {
reply.println(String.format("To use the `/%s` command, you need to be in the OpenJDK [census](https://openjdk.org/census)"
+ " and your GitHub account needs to be linked with your OpenJDK username"
+ " ([how to associate your GitHub account with your OpenJDK username]"
+ "(https://wiki.openjdk.org/display/skara#Skara-AssociatingyourGitHubaccountandyourOpenJDKusername)).", name()));
} else {
reply.println(String.format("To use the `/%s` command, you need to be listed as a contributor in this [census](%s)", name(), bot.censusRepo().authenticatedUrl()));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -69,10 +69,7 @@ public void handle(PullRequestBot bot, HostedCommit commit, LimitedCensusInstanc
return;
}
if (censusInstance.contributor(command.user()).isEmpty()) {
reply.println("To use the `/tag` command, you need to be in the OpenJDK [census](https://openjdk.org/census)"
+ " and your GitHub account needs to be linked with your OpenJDK username"
+ " ([how to associate your GitHub account with your OpenJDK username]"
+ "(https://wiki.openjdk.org/display/skara#Skara-AssociatingyourGitHubaccountandyourOpenJDKusername)).");
printInvalidUserWarning(bot, reply);
return;
}

Expand Down

0 comments on commit 3c63f2b

Please sign in to comment.