Skip to content

Commit

Permalink
Merge pull request #6 from quarkusio/adjust-permissions
Browse files Browse the repository at this point in the history
Adjust permission checks to avoid using teams API
  • Loading branch information
gsmet authored Nov 23, 2023
2 parents 58bf9a0 + c5e338e commit bab9e09
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/main/java/io/quarkus/bot/release/ReleaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueComment;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHTeam;
import org.kohsuke.github.GHUser;
import org.kohsuke.github.GHPermissionType;
import org.kohsuke.github.Reactable;
import org.kohsuke.github.ReactionContent;

Expand All @@ -31,7 +29,6 @@
import io.quarkus.bot.release.util.Command;
import io.quarkus.bot.release.util.Issues;
import io.quarkus.bot.release.util.Processes;
import io.quarkus.bot.release.util.Teams;

public class ReleaseAction {

Expand All @@ -51,7 +48,7 @@ void startRelease(Context context, Commands commands, @Issue.Opened GHEventPaylo
throw new IllegalStateException("No RELEASE_GITHUB_TOKEN around");
}

if (!hasReleaserPermission(issuePayload.getOrganization(), issuePayload.getSender())) {
if (!issuePayload.getRepository().hasPermission(issuePayload.getSender(), GHPermissionType.WRITE)) {
react(commands, issue, ReactionContent.MINUS_ONE);
issue.comment(":rotating_light: You don't have the permission to start a release.");
issue.close();
Expand All @@ -71,6 +68,8 @@ void startRelease(Context context, Commands commands, @Issue.Opened GHEventPaylo
throw e;
}

react(commands, issue, ReactionContent.PLUS_ONE);

handleSteps(context, commands, issuePayload.getIssue(), null, releaseInformation, new ReleaseStatus(Status.STARTED, Step.PREREQUISITES, StepStatus.STARTED, context.getGitHubRunId()));
}

Expand All @@ -84,7 +83,7 @@ void onComment(Context context, Commands commands, @IssueComment.Created GHEvent
return;
}

if (!hasReleaserPermission(issueCommentPayload.getOrganization(), issueCommentPayload.getSender())) {
if (!issueCommentPayload.getRepository().hasPermission(issueCommentPayload.getSender(), GHPermissionType.WRITE)) {
react(commands, issueComment, ReactionContent.MINUS_ONE);
return;
}
Expand Down Expand Up @@ -162,6 +161,8 @@ private void handleSteps(Context context, Commands commands, GHIssue issue, GHIs
continue;
}

commands.notice("Running step " + currentStep.getDescription());

try {
StepHandler stepHandler = getStepHandler(currentStep);

Expand Down Expand Up @@ -204,16 +205,6 @@ private void handleSteps(Context context, Commands commands, GHIssue issue, GHIs
}
}

private static boolean hasReleaserPermission(GHOrganization organization, GHUser user) {
try {
GHTeam releasersTeam = organization.getTeamBySlug(Teams.RELEASERS);
return releasersTeam.hasMember(user);
} catch (IOException e) {
LOG.error("Unable to verify permissions", e);
return false;
}
}

private static StepHandler getStepHandler(Step step) {
InstanceHandle<? extends StepHandler> instanceHandle = Arc.container().instance(step.getStepHandler());

Expand Down

0 comments on commit bab9e09

Please sign in to comment.