Skip to content

Commit

Permalink
Merge pull request #1197 from amihaiemil/1196
Browse files Browse the repository at this point in the history
#1996 started on Project renaming and left puzzles
  • Loading branch information
amihaiemil committed Aug 4, 2021
2 parents 6434567 + e95ea69 commit 432c8f0
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions self-api/src/main/java/com/selfxdsd/api/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ public interface Project {
*/
Repo deactivate(final Repo repo);

/**
* Rename this Project.
* @param newName New name of the project. It should be the simple repo
* name, without the owner (e.g. newName not user/newName).
*/
void rename(final String newName);

/**
* Create a wallet.
* @param billingInfo Billing info. Data about the Customer,
Expand Down
7 changes: 7 additions & 0 deletions self-api/src/main/java/com/selfxdsd/api/Projects.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@ Project getProjectById(
*/
void remove(final Project project);

/**
* Rename a Project and return the new instance.
* @param project Project to be renamed.
* @param newName New name of the project (simple name, without the owner).
* @return Project.
*/
Project rename(final Project project, final String newName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.13
* @todo #1196:60min When registering the Project webhook, make sure to also add
* the Repo Rename event to it. After that we might have to do it for Gitlab
* as well.
*/
final class GithubWebhooks implements Webhooks {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ public void remove(final Project project) {
}
}

@Override
public Project rename(
final Project project,
final String newName
) {
throw new UnsupportedOperationException(
"Projects of a PM are immutable, "
+ "can't rename one here. "
+ "Use Project.rename(...)."
);
}

@Override
public Iterator<Project> iterator() {
final Page page = super.current();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
* It should decide what kind of event has occurred and delegate it
* further to the ProjectManager who will deal with it. We still need
* the Issue Assigned case and Comment Created case.
* @todo #1996:30min Add the Project_Renamed case to the resolve(...) method
* and forward the call to the ProjectManager to take care of it.
* @todo #1196:30min Add unit tests for method rename(...) in this class.
*/
public final class StoredProject implements Project {

Expand Down Expand Up @@ -260,6 +263,35 @@ public Repo deactivate(final Repo repo) {
return repo;
}

@Override
public void rename(final String newName) {
final String provider = this.provider();
LOG.debug(
"Renaming Project " + this.repoFullName
+ " at " + provider + " to " + this.repoFullName.split("/")[0]
+ "/" + newName + "... "
);
final Webhooks hooks = this.projectManager.provider().repo(
this.repoFullName.split("/")[0],
this.repoFullName.split("/")[1]
).webhooks();
boolean noWebhooks = hooks.remove();
if(noWebhooks) {
LOG.debug("Successfully removed Webhooks! Renaming...");
final Project renamed = this.storage.projects()
.rename(this, newName);
LOG.debug("Project successfully renamed!");
boolean addedNewWebhook = hooks.add(renamed);
if(addedNewWebhook) {
LOG.debug("New Webhook successfully added!");
} else {
LOG.error("Failed to add new Webhook.");
}
} else {
LOG.error("Problem while removing webhooks. Rename aborted.");
}
}

@Override
public Wallet createStripeWallet(final BillingInfo billingInfo) {
LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ public void remove(final Project project) {
}
}

@Override
public Project rename(final Project project, final String newName) {
throw new UnsupportedOperationException(
"Projects of a User are immutable, "
+ "can't rename one here. "
+ "Use Project.rename(...)."
);
}

@Override
public Iterator<Project> iterator() {
final Page page = super.current();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public void remove(final Project project) {
throw new UnsupportedOperationException("Not yet implemented.");
}

@Override
public Project rename(final Project project, final String newName) {
throw new UnsupportedOperationException("Not yet implemented.");
}

@Override
public Iterator<Project> iterator() {
final Page page = super.current();
Expand Down

0 comments on commit 432c8f0

Please sign in to comment.