Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arc 1456 auto app creation #1401

Merged
merged 17 commits into from
Aug 2, 2022
Merged

Arc 1456 auto app creation #1401

merged 17 commits into from
Aug 2, 2022

Conversation

Harminder84
Copy link
Contributor

@Harminder84 Harminder84 commented Jul 22, 2022

What's in this PR?
Automatic app creation has been implemented using App manifest flow.

Sequence diagram

App manifest flow

Video demonstrating the feature

Screen.Recording.2022-07-25.at.4.07.55.pm.mov

Why
This is one of the options to create GitHub app for enterpise

Added feature flags
Existing flag GHE_SERVER

Affected issues
ARC-1456

How has this been tested?
Unit test cases added for new routes

@@ -0,0 +1,34 @@
{
"name": "ghe-app-for-jira",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want this to be an empty string right? Otherwise this will auto-fill the input for every customer which they will then have to delete.

Copy link
Contributor Author

@Harminder84 Harminder84 Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rachellerathbone, don't we want to give any relevant default name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a bad idea, however, something to consider is that the name has to be unique per server...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caught up with Jade on this one and she agrees it should be blank. From a UX standpoint, we'd only pre-populate an input field if it wasn't clear what a user is meant to enter. However, is this case, app name is pretty straightforward. Plus, to @mboudreau's point: GH app names need to be unique per server so they second a customer tries to create a second app, this would fail.

Just out of curiosity, what happens when you try and add an existing app name in the input? Guessing GH renders some kind of error but want to be sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GH renders error if you try to add an exisiting app name -

Screen Shot 2022-07-27 at 3 16 08 pm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly you can proceed without giving app name and will eventually fails when trying to complete app manifest flow. Not sure issue with specific version of GH Enterprise.

@rachellerathbone
Copy link
Contributor

Can you add a video recording of the implementation now that you've included the whole flow (from clicking 'create' on auto/manual through to the redirect screen).

@@ -0,0 +1,15 @@
<!doctype html>
Copy link
Contributor Author

@Harminder84 Harminder84 Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This temporary page is created to test the flow. Actual page will be developed as part of another ticket.

Copy link
Collaborator

@krazziekay krazziekay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to add test cases for the new routes.

installationId: installation.id
});
req.session.temp = undefined;
res.json({ success:true });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to render app installation page which is part of another ticket and is in progress.

@Harminder84 Harminder84 marked this pull request as ready for review July 25, 2022 06:26
@Harminder84 Harminder84 requested a review from a team as a code owner July 25, 2022 06:26
import { Installation } from "~/src/models/installation";

export const GithubManifestCompleteGet = async (req: Request, res: Response) => {
const uuid = req.params.uuid;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming from redirect_url where UUID is part of path parameter.
"redirect_url": "<<APP_HOST>>/github/manifest/<<UUID>>/complete"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can put both uuid and gheHost in the session cookie, as sessio cookie is signed cannot be tempered.

@@ -0,0 +1,22 @@
const params = new URLSearchParams(window.location.search.substring(1));
const gheHost = params.get("serverUrl");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we passing this as a param? In jira-server-url.js it looks like we're setting customData to an empty object if no app exists const customData = data.appExists ? { serverUrl: gheServerURL } : {}; so from empty state we're never passing this value to the URL. And then in github-app-creation.js the only thing we're pulling from params is the jiraHost. So my guess here is that gheHost will be null.

We need to fix this and also add error handling in the event there isn't a gheHost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct @rachellerathbone. I discussed with @krazziekay, he already worked on it and serverUrl will be available in URL once his PR gets merged.

Comment on lines 4 to 8
"redirect_url": "<<APP_HOST>>/github/manifest/<<UUID>>/complete",
"hook_attributes": {
"url": "<<APP_HOST>>/github/<<UUID>>/events"
},
"setup_url": "<<APP_HOST>>/github/<<UUID>>/setup",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the flow here? UUID is setup beforehand but the app is not installed yet, so what's the point of having the UUID there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, keep in mind that we might use this app manifest for our own dev flow. As might want to keep it a bit more abstracted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow is. : -

  1. Construct JSON for GitHub app
  2. Submit JSON data to GitHub Enterprise
  3. GitHub Enterpise redirected back to redirect_url with code which is supplied as JSON data
  4. Exchage code with GitHub Enterprise
  5. Save data to GitHubServerApps table

When we're submitting data to GH Enterprise in step 2, we need to construct setup_url, webhook_url and others with UUID.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mboudreau do you have thoughts on how we should handle the url value here? This is required and is meant to link to the apps homepage. However, we don't have the app name at this point (even if we prepopulate, people can edit it). The best I can see us doing is entering <<APP_HOST>>/apps/ and adding messaging somewhere in the auto flow to let customers know they will need to update this in their settings manually?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should get together on this, but my understanding is that we shouldn't create any apps on our end until the github flow is done, which will provide us with everything we need to create the app in our DB. Creating the app beforehand means that the process might not finish and we'll have apps that were never created...

Comment on lines +35 to +37
temp?: {
[key: string]: any;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this addition and why it's needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to store GHE Host in session that can be fetched when user redirect back to redirect_url from GitHub Enterprise.

Copy link
Contributor

@mboudreau mboudreau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few issues that needs addressing

@@ -0,0 +1,34 @@
{
"name": "ghe-app-for-jira",
"url": "https://github.com/marketplace/jira-software-github",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rachellerathbone, what should be the URL for GHE app? Right now, I'm using the cloud app URL here.

import { Installation } from "~/src/models/installation";

export const GithubManifestCompleteGet = async (req: Request, res: Response) => {
const uuid = req.params.uuid;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming from redirect_url where UUID is part of path parameter.
"redirect_url": "<<APP_HOST>>/github/manifest/<<UUID>>/complete"

Comment on lines +35 to +37
temp?: {
[key: string]: any;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to store GHE Host in session that can be fetched when user redirect back to redirect_url from GitHub Enterprise.

Comment on lines 4 to 8
"redirect_url": "<<APP_HOST>>/github/manifest/<<UUID>>/complete",
"hook_attributes": {
"url": "<<APP_HOST>>/github/<<UUID>>/events"
},
"setup_url": "<<APP_HOST>>/github/<<UUID>>/setup",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow is. : -

  1. Construct JSON for GitHub app
  2. Submit JSON data to GitHub Enterprise
  3. GitHub Enterpise redirected back to redirect_url with code which is supplied as JSON data
  4. Exchage code with GitHub Enterprise
  5. Save data to GitHubServerApps table

When we're submitting data to GH Enterprise in step 2, we need to construct setup_url, webhook_url and others with UUID.

@@ -0,0 +1,22 @@
const params = new URLSearchParams(window.location.search.substring(1));
const gheHost = params.get("serverUrl");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct @rachellerathbone. I discussed with @krazziekay, he already worked on it and serverUrl will be available in URL once his PR gets merged.

@@ -0,0 +1,34 @@
{
"name": "ghe-app-for-jira",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GH renders error if you try to add an exisiting app name -

Screen Shot 2022-07-27 at 3 16 08 pm

@@ -0,0 +1,34 @@
{
"name": "ghe-app-for-jira",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly you can proceed without giving app name and will eventually fails when trying to complete app manifest flow. Not sure issue with specific version of GH Enterprise.

static/js/jira-app-creation.js Outdated Show resolved Hide resolved
static/js/jira-redirect.js Outdated Show resolved Hide resolved
import { Installation } from "~/src/models/installation";

export const GithubManifestCompleteGet = async (req: Request, res: Response) => {
const uuid = req.params.uuid;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can put both uuid and gheHost in the session cookie, as sessio cookie is signed cannot be tempered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants