Skip to content

Commit

Permalink
Merge pull request #280 from eclipse-mylyn/37_gitlab_connector
Browse files Browse the repository at this point in the history
add milestone, labels and personalAccessToken #37
  • Loading branch information
BeckerFrank authored Sep 3, 2023
2 parents e72bf66 + 6574dcf commit fa4b854
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bundle-SymbolicName: org.eclipse.mylyn.gitlab.core;singleton:=true
Bundle-Vendor: %Bundle-Vendor
Bundle-Version: 4.0.0.qualifier
Export-Package: org.eclipse.mylyn.gitlab.core,
org.eclipse.mylyn.internal.gitlab.core;x-internal:=true
org.eclipse.mylyn.internal.gitlab.core;x-friends:="org.eclipse.mylyn.gitlab.ui"
Import-Package: com.google.common.base;version="31.1.0",
com.google.common.cache;version="31.1.0",
com.google.common.collect;version="31.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;

Expand All @@ -27,166 +28,203 @@
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskOperation;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

public final class GitlabConfiguration implements Serializable {

private static final long serialVersionUID = -6859757478504901423L;
private static final long serialVersionUID = 3705325855842441295L;

private static final GitlabTaskSchema SCHEMA = GitlabTaskSchema.getDefault();
private final String repositoryURL;
private BigInteger userID;
private JsonElement userDetails;
private Map<String, JsonElement> projectDetailsMap = new HashMap<>();
private Map<Integer, JsonElement> projectIDsMap = new HashMap<>();
private ArrayList<JsonElement> projects = new ArrayList<>();
private Map<String, JsonElement> groupsDetailsMap = new HashMap<>();
private List<JsonElement> groups = new ArrayList<JsonElement>();
private class GitlabProjectDetail {
private JsonObject project;
private Map<String, JsonElement> labelsHash = new HashMap<>();
private Map<String, JsonElement> milestonesHash = new HashMap<>();

public GitlabConfiguration(String repositoryURL) {
this.repositoryURL = repositoryURL;
public GitlabProjectDetail(JsonObject project, JsonArray labels, JsonArray milestones) {
this.project = project;
for (JsonElement jsonElement : labels) {
JsonObject jsonObject = (JsonObject) jsonElement;
labelsHash.put(jsonObject.get("name").getAsString(), jsonObject);
}
for (JsonElement jsonElement : milestones) {
JsonObject jsonObject = (JsonObject) jsonElement;
milestonesHash.put(jsonObject.get("id").getAsString(), jsonObject);
}
}

public String getRepositoryURL() {
return repositoryURL;
public JsonObject getProject() {
return project;
}

public BigInteger getUserID() {
return userID;
public Set<String> getLabelNames() {
return labelsHash.keySet();
}

public void setUserID(BigInteger userID) {
this.userID = userID;
public Map<String, JsonElement> getMilestones() {
return milestonesHash;
}

public JsonElement getUserDetails() {
return userDetails;
}
}

public void setUserDetails(JsonElement userDetails) {
this.userDetails = userDetails;
}
private static final GitlabTaskSchema SCHEMA = GitlabTaskSchema.getDefault();
private final String repositoryURL;
private BigInteger userID;
private JsonElement userDetails;
private Map<Integer, GitlabProjectDetail> projectIDsMap = new HashMap<>();
private Map<String, JsonElement> groupsDetailsMap = new HashMap<>();
private List<JsonElement> groups = new ArrayList<JsonElement>();

public ArrayList<JsonElement> getProjects() {
return projects;
}
public GitlabConfiguration(String repositoryURL) {
this.repositoryURL = repositoryURL;
}

public void addProject(JsonElement project) {
projects.add(project);
projectDetailsMap.put(project.getAsJsonObject().get("name_with_namespace").getAsString(), project);
projectIDsMap.put(project.getAsJsonObject().get("id").getAsInt(), project);
}
public String getRepositoryURL() {
return repositoryURL;
}

public JsonElement getProjcetDetail(String project) {
return projectDetailsMap.get(project);
}
public BigInteger getUserID() {
return userID;
}

public JsonElement getProjcetDetailFromNumber(Integer id) {
return projectIDsMap.get(id);
}
public void setUserID(BigInteger userID) {
this.userID = userID;
}

public JsonElement getGroupDetail(String project) {
return groupsDetailsMap.get(project);
}
public JsonElement getUserDetails() {
return userDetails;
}

public Set<String> getProjectNames() {
return projectDetailsMap.keySet();
}
public void setUserDetails(JsonElement userDetails) {
this.userDetails = userDetails;
}

public Set<String> getGroupNames() {
return groupsDetailsMap.keySet();
}
public void addProject(JsonElement project, JsonElement lables, JsonElement milestones) {
GitlabProjectDetail gitlabProject = new GitlabProjectDetail(project.getAsJsonObject(), lables.getAsJsonArray(),
milestones.getAsJsonArray());
projectIDsMap.put(project.getAsJsonObject().get("id").getAsInt(), gitlabProject);
}

public List<JsonElement> getGroups() {
return groups;
}

public void addGroup(JsonElement group) {
groups.add(group);
groupsDetailsMap.put(group.getAsJsonObject().get("full_path").getAsString(), group);
public Set<Integer> getProjectIDs() {
return projectIDsMap.keySet();
}

}
public JsonElement getGroupDetail(String group) {
return groupsDetailsMap.get(group);
}

public boolean updateProductOptions(@NonNull TaskData taskData) {
if (taskData == null) {
return false;
}
TaskAttribute attributeProduct = taskData.getRoot().getMappedAttribute(SCHEMA.PRODUCT.getKey());
public Set<String> getGroupNames() {
return groupsDetailsMap.keySet();
}

if (attributeProduct == null) {
return false;
}
for (JsonElement product : projects) {
JsonObject productObject = (JsonObject) product;
attributeProduct.putOption(productObject.get("id").getAsString(),
productObject.get("name_with_namespace").getAsString());
}
TaskAttribute priorityAttrib = taskData.getRoot().getMappedAttribute(SCHEMA.PRIORITY.getKey());
if (priorityAttrib != null) {
priorityAttrib.putOption("CRITICAL", "critical");
priorityAttrib.putOption("HIGH", "high");
priorityAttrib.putOption("MEDIUM", "Medium");
priorityAttrib.putOption("LOW", "low");
priorityAttrib.putOption("UNKNOWN", "unknown");
}
public void addGroup(JsonElement group) {
groups.add(group);
groupsDetailsMap.put(group.getAsJsonObject().get("full_path").getAsString(), group);

TaskAttribute typeAttrib = taskData.getRoot().getMappedAttribute(SCHEMA.ISSUE_TYPE.getKey());
if (typeAttrib != null) {
typeAttrib.putOption("issue", "Issue");
typeAttrib.putOption("incident", "Incident");
}
}

return true;
public boolean updateProductOptions(@NonNull TaskData taskData) {
if (taskData == null) {
return false;
}
TaskAttribute attributeProduct = taskData.getRoot().getMappedAttribute(SCHEMA.PRODUCT.getKey());
TaskAttribute attributeLabels = taskData.getRoot().getMappedAttribute(SCHEMA.TASK_LABELS.getKey());
TaskAttribute attributeMilestone = taskData.getRoot().getMappedAttribute(SCHEMA.TASK_MILESTONE.getKey());

public boolean updateQueryOptions(@NonNull TaskData taskData) {
if (taskData == null) {
return false;
}

TaskAttribute attributeGroups = taskData.getRoot().getMappedAttribute("GROUP");
if (attributeGroups != null) {
Set<String> groups = getGroupNames();
for (String string : groups) {
attributeGroups.putOption(string, string);
}
}
TaskAttribute stateAttrib = taskData.getRoot().getMappedAttribute("STATE");
if (stateAttrib != null) {
stateAttrib.putOption("opened", "Opened");
stateAttrib.putOption("closed", "Closed");
stateAttrib.putOption("", "All");
}
return updateProductOptions(taskData);
if (attributeProduct == null) {
return false;
}

public String getGroupID(String path) {
Optional<Object> groupId = Optional.ofNullable(groupsDetailsMap.get(path))
.map(ma -> ma.getAsJsonObject().get("id").getAsString());
if (groupId.isPresent()) {
return (String) groupId.get();
}
return "";
for (GitlabProjectDetail product : projectIDsMap.values()) {
JsonObject productObject = product.getProject();
if (attributeProduct != null) {
attributeProduct.putOption(productObject.get("id").getAsString(),
productObject.get("name_with_namespace").getAsString());
}
}
if (attributeProduct.getValue() != null && !attributeProduct.getValue().isBlank()) {
for (String label : projectIDsMap.get(Integer.parseInt(attributeProduct.getValue())).getLabelNames()) {
attributeLabels.putOption(label, label);
}
}
if (attributeProduct.getValue() != null && !attributeProduct.getValue().isBlank()) {
for (Entry<String, JsonElement> milestone : projectIDsMap.get(Integer.parseInt(attributeProduct.getValue()))
.getMilestones().entrySet()) {
attributeMilestone.putOption(milestone.getKey(),
milestone.getValue().getAsJsonObject().get("title").getAsString());
}
}

public void addValidOperations(TaskData bugReport) {
TaskAttribute attributeStatus = bugReport.getRoot().getMappedAttribute(TaskAttribute.STATUS);
String attributeStatusValue = attributeStatus.getValue();
TaskAttribute operationAttribute = bugReport.getRoot().getAttribute(TaskAttribute.OPERATION);
if (operationAttribute == null) {
operationAttribute = bugReport.getRoot().createAttribute(TaskAttribute.OPERATION);
}
TaskOperation.applyTo(operationAttribute, attributeStatusValue, attributeStatusValue);

TaskAttribute attribute = bugReport.getRoot().createAttribute(TaskAttribute.PREFIX_OPERATION + "opened");
TaskOperation.applyTo(attribute, attributeStatusValue, attributeStatusValue);

attribute = bugReport.getRoot().createAttribute(TaskAttribute.PREFIX_OPERATION + "closed");
if (attributeStatusValue.equals("closed")) {
TaskOperation.applyTo(attribute, "reopen", "Reopen");
} else {
TaskOperation.applyTo(attribute, "close", "Close");
}
TaskAttribute priorityAttrib = taskData.getRoot().getMappedAttribute(SCHEMA.PRIORITY.getKey());
if (priorityAttrib != null) {
priorityAttrib.putOption("CRITICAL", "critical");
priorityAttrib.putOption("HIGH", "high");
priorityAttrib.putOption("MEDIUM", "Medium");
priorityAttrib.putOption("LOW", "low");
priorityAttrib.putOption("UNKNOWN", "unknown");
}

TaskAttribute typeAttrib = taskData.getRoot().getMappedAttribute(SCHEMA.ISSUE_TYPE.getKey());
if (typeAttrib != null) {
typeAttrib.putOption("issue", "Issue");
typeAttrib.putOption("incident", "Incident");
}

return true;
}

public boolean updateQueryOptions(@NonNull TaskData taskData) {
if (taskData == null) {
return false;
}

TaskAttribute attributeGroups = taskData.getRoot().getMappedAttribute("GROUP");
if (attributeGroups != null) {
Set<String> groups = getGroupNames();
for (String string : groups) {
attributeGroups.putOption(string, string);
}
}
TaskAttribute stateAttrib = taskData.getRoot().getMappedAttribute("STATE");
if (stateAttrib != null) {
stateAttrib.putOption("opened", "Opened");
stateAttrib.putOption("closed", "Closed");
stateAttrib.putOption("", "All");
}
TaskAttribute searchinAttrib = taskData.getRoot().getMappedAttribute("SEARCH_IN");
if (searchinAttrib != null) {
searchinAttrib.putOption("title", "Title");
searchinAttrib.putOption("description", "Description");
searchinAttrib.putOption("", "Title and Description");
}
return updateProductOptions(taskData);
}

public String getGroupID(String path) {
Optional<Object> groupId = Optional.ofNullable(groupsDetailsMap.get(path))
.map(ma -> ma.getAsJsonObject().get("id").getAsString());
if (groupId.isPresent()) {
return (String) groupId.get();
}
return "";
}

public void addValidOperations(TaskData bugReport) {
TaskAttribute attributeStatus = bugReport.getRoot().getMappedAttribute(TaskAttribute.STATUS);
String attributeStatusValue = attributeStatus.getValue();
TaskAttribute operationAttribute = bugReport.getRoot().getAttribute(TaskAttribute.OPERATION);
if (operationAttribute == null) {
operationAttribute = bugReport.getRoot().createAttribute(TaskAttribute.OPERATION);
}
TaskOperation.applyTo(operationAttribute, attributeStatusValue, attributeStatusValue);

TaskAttribute attribute = bugReport.getRoot().createAttribute(TaskAttribute.PREFIX_OPERATION + "opened");
TaskOperation.applyTo(attribute, attributeStatusValue, attributeStatusValue);

attribute = bugReport.getRoot().createAttribute(TaskAttribute.PREFIX_OPERATION + "closed");
if (attributeStatusValue.equals("closed")) {
TaskOperation.applyTo(attribute, "reopen", "Reopen");
} else {
TaskOperation.applyTo(attribute, "close", "Close");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public final class GitlabCoreActivator extends Plugin {
public static final String PROJECTS = "gitlab.projects";
public static final String AVANTAR = "gitlab.avantar";
public static final String SHOW_COMMENT_ICONS = "gitlab.show.comment.icons";
public static final String USE_PERSONAL_ACCESS_TOKEN = "gitlab.use.personal.access.token";
public static final String PERSONAL_ACCESS_TOKEN = "gitlab.personal.access.token";
public static final String API_VERSION = "/api/v4";

// The shared instance
Expand Down
Loading

0 comments on commit fa4b854

Please sign in to comment.