mylyn-gitea/io.gitea.mylyn.core/src/io/gitea/mylyn/core/GiteaAction.java

65 lines
1.3 KiB
Java

// Copyright (c) 2021, Fr.Terrot. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package io.gitea.mylyn.core;
import io.gitea.model.IssueState;
import io.gitea.model.Issue;
/**
* Represents an action that tell Gitea what to do with the issue, e.g. "close"
* will close the issue in Gitea. This wrapper is necessary.
*
*/
public enum GiteaAction {
LEAVE("leave"), CLOSE("close"), REOPEN("reopen");
/**
* The valid actions for an open issue
*/
private final static GiteaAction[] opened = { LEAVE, CLOSE };
/**
* The valid actions for a closed issue
*/
private final static GiteaAction[] closed = { LEAVE, REOPEN };
private GiteaAction(String label) {
this.label = label;
}
public final String label;
/**
* Returns all valid actions for the given issue.
*
* @param issue
* @return
*/
public static GiteaAction[] getActions(Issue issue) {
if (IssueState.isClosed(issue)) {
return closed;
} else {
return opened;
}
}
/**
* Returns the GiteaAction enum for the given action string.
*
* @param action
* @return
*/
public static GiteaAction find(String action) {
for (GiteaAction a : values()) {
if (a.label.equals(action)) {
return a;
}
}
return LEAVE;
}
}