Skip to content

Commit

Permalink
fixed the back button after account linking. fixed creating an api at…
Browse files Browse the repository at this point in the history
… the root of a repo in github. fixes #159.  fixes #158
  • Loading branch information
EricWittmann committed Aug 15, 2017
1 parent fb33572 commit 2c596a0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
public class GitHubResourceResolver {

private static Pattern pattern1 = Pattern.compile("https://github.com/([^/]+)/([^/]+)/blob/[^/]+/(.*.json)");
private static Pattern pattern2 = Pattern.compile("https://github.com/([^/]+)/([^/]+)/[^/]+/(.*.json)");
private static Pattern pattern3 = Pattern.compile("https://raw.githubusercontent.com/([^/]+)/([^/]+)/[^/]+/(.*.json)");
private static Pattern pattern2 = Pattern.compile("https://raw.githubusercontent.com/([^/]+)/([^/]+)/[^/]+/(.*.json)");

/**
* Resolves a github URL into a resource object. The URL must be of the proper format.
Expand Down Expand Up @@ -63,18 +62,6 @@ public static GitHubResource resolve(String ghUrl) {
return resource;
}

matcher = pattern3.matcher(ghUrl);
if (matcher.matches()) {
GitHubResource resource = new GitHubResource();
String org = matcher.group(1);
String repo = matcher.group(2);
String path = matcher.group(3);
resource.setOrganization(org);
resource.setRepository(repo);
resource.setResourcePath(path);
return resource;
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public void testResolve() {
Assert.assertEquals("Apicurio", resource.getOrganization());
Assert.assertEquals("api-samples", resource.getRepository());
Assert.assertEquals("apiman-rls/apiman-rls.json", resource.getResourcePath());

resource = GitHubResourceResolver.resolve("https://github.com/Apicurio/api-samples/blob/master/pet-store.json");
Assert.assertNotNull(resource);
Assert.assertEquals("Apicurio", resource.getOrganization());
Assert.assertEquals("api-samples", resource.getRepository());
Assert.assertEquals("pet-store.json", resource.getResourcePath());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ export class CreateApiFormComponent {
api.name = this.model.name;
api.description = this.model.description;
if (this.model.accountType === "GitHub") {
api.repositoryUrl = "https://github.com/" + this.model.github.organization + "/" + this.model.github.repository + this.model.github.resource;
let sep: string = "";
if (this.model.github.resource && this.model.github.resource[0] !== '/') {
sep = "/";
}
api.repositoryUrl = "https://github.com/" +
this.model.github.organization + "/" +
this.model.github.repository + "/blob/master" + sep +
this.model.github.resource;
} else if (this.model.accountType === "GitLab") {
} else if (this.model.accountType === "Bitbucket") {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h2 class="card-pf-title">
</div>

<!-- Please Wait, Linking... -->
<div class="card-pf card-pf-accented" *ngIf="!isLinkError()">
<div class="card-pf card-pf-accented" *ngIf="!alreadyCompleted && !isLinkError()">
<div class="card-pf-heading">
<h2 class="card-pf-title">
<span class="fa fa-fw fa-info"></span>
Expand All @@ -58,11 +58,30 @@ <h2 class="card-pf-title">
moment, after which you will be redirected back to the
<a [routerLink]="['/settings/accounts']">Settings &gt;&gt; Accounts</a> page.
</p>
<p class="in-progress"><span class="spinner spinner-xs spinner-inline"></span> Finalizing linked account, please wait...</p>
<p class="in-progress"><span class="spinner spinner-xs spinner-inline"></span> Finalizing account link, please wait...</p>
<div class="actions">
</div>
</div>
</div>

<!-- Action Already Completed -->
<div class="card-pf card-pf-accented" *ngIf="alreadyCompleted">
<div class="card-pf-heading">
<h2 class="card-pf-title">
<span class="fa fa-fw fa-info-circle"></span>
<span>Action Already Completed</span>
</h2>
</div>
<div class="card-pf-body">
<p>
This account has already been successfully linked. Click the button below
to return to the Settings page.
</p>
<div class="actions">
<a class="btn btn-default" routerLink="/settings/accounts">Back to Accounts</a>
</div>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class CreatedLinkedAccountPageComponent extends AbstractPageComponent {
accountType: string;
linkError: string;
nonce: string;
alreadyCompleted: boolean = false;

/**
* C'tor.
Expand Down Expand Up @@ -62,9 +63,14 @@ export class CreatedLinkedAccountPageComponent extends AbstractPageComponent {
console.info("Nonce: %s", this.nonce);

if (!this.isLinkError()) {
this.accountsApi.completeLinkedAccount(this.accountType, this.nonce).then( () => {
this.router.navigate(["/settings/accounts"]);
}).catch( error => this.error(error));
if (this.nonce) {
this.accountsApi.completeLinkedAccount(this.accountType, this.nonce).then(() => {
localStorage.removeItem(ACCOUNT_LINK_NONCE_KEY + "." + this.accountType);
this.router.navigate(["/settings/accounts"]);
}).catch(error => this.error(error));
} else {
this.alreadyCompleted = true;
}
} else {
this.accountsApi.deleteLinkedAccount(this.accountType).then( () => {
console.info("[CreatedLinkedAccountPageComponent] Deleted the (failed) linked account.");
Expand Down

0 comments on commit 2c596a0

Please sign in to comment.