Skip to content

Commit

Permalink
Merge pull request #1055 from fellahi-ali/#1013
Browse files Browse the repository at this point in the history
#1013 Start implementing BitbucketRepo::issues()
  • Loading branch information
amihaiemil authored Mar 13, 2021
2 parents 6bacc83 + 04f191f commit 7d57a00
Show file tree
Hide file tree
Showing 6 changed files with 847 additions and 4 deletions.
179 changes: 179 additions & 0 deletions self-core-impl/src/main/java/com/selfxdsd/core/BitbucketIssue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/**
* Copyright (c) 2020-2021, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core;

import com.selfxdsd.api.*;
import com.selfxdsd.api.storage.Storage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.json.JsonObject;
import java.net.URI;

/**
* An Issue in a Bitbucket repository.
* @author Ali Fellahi ([email protected])
* @version $Id$
* @since 0.0.69
*
* @todo #1013:60min Continue on the impl. & tests for BitbucketIssue class.
*/
final class BitbucketIssue implements Issue {

/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(
BitbucketIssue.class
);

/**
* Issue base uri.
*/
private final URI issueUri;

/**
* Issue JSON as returned by Github's API.
*/
private final JsonObject json;

/**
* Self storage, in case we want to store something.
*/
private final Storage storage;

/**
* Github's JSON Resources.
*/
private final JsonResources resources;

/**
* Ctor.
* @param issueUri Issues base URI.
* @param json Json Issue as returned by Github's API.
* @param storage Storage.
* @param resources Github's JSON Resources.
*/
BitbucketIssue(
final URI issueUri,
final JsonObject json,
final Storage storage,
final JsonResources resources
) {
this.issueUri = issueUri;
this.json = json;
this.storage = storage;
this.resources = resources;
}

@Override
public String issueId() {
return String.valueOf(this.json.getInt("id"));
}

@Override
public String provider() {
return Provider.Names.BITBUCKET;
}

@Override
public String role() {
final String role;
if(this.isPullRequest()) {
role = Contract.Roles.REV;
} else {
role = Contract.Roles.DEV;
}
return role;
}

@Override
public String repoFullName() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public String author() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public String body() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public String assignee() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public boolean assign(final String username) {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public boolean unassign(final String username) {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public JsonObject json() {
return this.json;
}

@Override
public Comments comments() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public void close() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public void reopen() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public boolean isClosed() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public boolean isPullRequest() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public Estimation estimation() {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public Labels labels() {
throw new UnsupportedOperationException("Not implemented yet");
}
}
162 changes: 162 additions & 0 deletions self-core-impl/src/main/java/com/selfxdsd/core/BitbucketIssues.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* Copyright (c) 2020-2021, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core;

import com.selfxdsd.api.Issue;
import com.selfxdsd.api.Issues;
import com.selfxdsd.api.Repo;
import com.selfxdsd.api.storage.Storage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.json.JsonObject;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.Iterator;

/**
* Issues in a Bitbucket repository.
* @author Ali Fellahi ([email protected])
* @version $Id$
* @since 0.0.69
*
* @todo #1013:60min Continue the implementation & tests of open()
* and search() methods.
*/
final class BitbucketIssues implements Issues {

/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(
BitbucketIssues.class
);

/**
* Bitbucket repo issues base uri.
*/
private final URI issuesUri;

/**
* Bitbucket's JSON Resources.
*/
private final JsonResources resources;

/**
* Parent Repo.
*/
private final Repo repo;

/**
* Self storage, in case we want to store something.
*/
private final Storage storage;

/**
* Ctor.
*
* @param resources Bitbucket's JSON Resources.
* @param issuesUri Issues base URI.
* @param repo Parent repo.
* @param storage Storage.
*/
BitbucketIssues(
final JsonResources resources,
final URI issuesUri,
final Repo repo,
final Storage storage
) {
this.resources = resources;
this.issuesUri = issuesUri;
this.repo = repo;
this.storage = storage;
}

@Override
public Issue getById(final String issueId) {
LOG.debug("Getting Bitbucket issue with id " + issueId + "...");
final URI issueUri = URI.create(
this.issuesUri.toString() + "/" + issueId
);
final Resource resource = this.resources.get(issueUri);
JsonObject jsonObject;
switch (resource.statusCode()) {
case HttpURLConnection.HTTP_OK:
jsonObject = resource.asJsonObject();
break;
case HttpURLConnection.HTTP_NOT_FOUND:
case HttpURLConnection.HTTP_GONE:
jsonObject = null;
break;
default:
throw new IllegalStateException(
"Could not get the issue " + issueId + ". "
+ "Received status code: " + resource.statusCode()
);
}
Issue issue = null;
if(jsonObject != null){
issue = new BitbucketIssue(
issueUri,
jsonObject,
this.storage,
this.resources
);
}
return issue;
}

@Override
public Issue received(final JsonObject issue) {
return new BitbucketIssue(
URI.create(
this.issuesUri.toString() + "/" + issue.getInt("id")
),
issue,
this.storage,
this.resources
);
}

@Override
public Issue open(
final String title,
final String body,
final String... labels
) {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public Issues search(final String text, final String... labels) {
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
public Iterator<Issue> iterator() {
throw new IllegalStateException(
"You cannot iterate over all the issues in a repo."
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ public String fullName() {

@Override
public Issues issues() {
throw new UnsupportedOperationException("Not implemented yet");
return new BitbucketIssues(
this.resources(),
URI.create(this.repoUri().toString() + "/issues"),
this,
this.storage()
);
}

@Override
Expand Down
Loading

0 comments on commit 7d57a00

Please sign in to comment.