Skip to content

Commit

Permalink
fixed pizzly replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
Moneexa committed Nov 30, 2023
1 parent 4521776 commit 918b1e6
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 200 deletions.
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ Note that, even when you run it locally, you need to connect to GitHub to use an
### Using End-2-End Tests Locally

We use [Cypress](https://www.cypress.io/) for e2e testing.
The CI pipeline provides the necessary Pizzly `authId` as an ENV variable.
The CI pipeline provides the necessary Oauth `authId` as an ENV variable.
Locally, however, you'll need to provide one yourself.
You can either set `CYPRESS_PIZZLY_E2E_AUTH_ID` containing the `authId` or create a `cypress.env.json` file and fill it with the following content:
You can either set `CYPRESS_OAUTH_E2E_AUTH_ID` and `CYPRESS_USER` containing the `authId` and `user` or create a `cypress.env.json` file and fill it with the following content:

```json
{
"PIZZLY_E2E_AUTH_ID": "*********"
"OAUTH_E2E_AUTH_ID": "*********",
"USER": "***********"
}
```

The value of `PIZZLY_E2E_AUTH_ID` needs to be a valid `authId` from an active Pizzly session, which you can obtain a) via the Pizzly dashboard (see below) or b) in the local storage (Chrome developer console -> Application -> Storage -> Local Storage -> `http://localhost:8080` -> `authId`)
The value of `OAUTH_E2E_AUTH_ID` and `USER` needs to be a valid `authId` and `user` from an active OAuth session, which you can obtain in the local storage (Chrome developer console -> Application -> Storage -> Local Storage -> `http://localhost:8080` -> `authId`, `user`)
The involved GitHub account also needs to have developer access to the repo `adr/adr-test-repository-empty`.
Lastly, don't forget to start the app before running the e2e tests (`npm start`).

Expand Down Expand Up @@ -104,23 +105,14 @@ npm run format

### Backend Setup

The project uses [Pizzly](https://github.com/bearer/pizzly) for the authentication to GitHub.
Our Pizzly instance is hosted on Heroku.
The project uses [OAuth] for the authentication to GitHub.
If you do not want to use this instance, you can easily set up your own by following these steps:

1. Create an OAuth application on GitHub (see [here](https://docs.github.com/en/github-ae@latest/developers/apps/creating-an-oauth-app)).
- Copy the Client ID and Client Secret of the app (you'll need them later).
- Set the callback URL to `https://[your-app-name].herokuapp.com/auth/callback`, where `[your-app-name]` is the name of the Heroku app you'll create in the next step.
1. Deploy your own Pizzly instance on Heroku as described at <https://github.com/bearer/pizzly>.
1. Configure the deployed Pizzly instance.
- Open the Pizzly dashboard (`https://{your-app-name}.herokuapp.com`).
- Add a new API and choose `GitHub`, then create a new configuration for it.
- Enter the `Client ID` and `Client Secret` of your GitHub OAuth app.
- As `scopes`, enter `repo`.
- Also, consider [securing your Pizzly instance](https://github.com/Bearer/Pizzly/blob/master/docs/securing-your-instance.md).
1. Update `src/config.js` with the connection details of your Pizzly instance:
- Set `pizzlyHost` to the base URL of your Pizzly instance, e.g. `https://{your-app-name}.herokuapp.com/`.
- If you secured Pizzly: set `pizzlyPublishableKey` to your publishableKey.
2. Create a Github app on Firebase and in its configurations, set the Client ID and Client Secret as copied from the above Github app

- Set the callback URL in Github Oauth app configuration to the one provided by Firebase.

## Project Context

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/adrManagerTest/AddNewAdr.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_BASE_URL } from "../../support/e2e";
import { GRAPHQL_URL, TEST_BASE_URL } from "../../support/e2e";

context("Adding a new ADR to a repo", () => {
it("Create a new ADR", () => {
Expand All @@ -8,7 +8,7 @@ context("Adding a new ADR to a repo", () => {
cy.visit(TEST_BASE_URL);

// add the ADR-Manager repo
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.intercept('POST', GRAPHQL_URL).as("getRepos");
cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=listRepo]").contains("ADR-Manager").click();
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/adrManagerTest/AddRepo.cy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TEST_BASE_URL } from "../../support/e2e";
import { GRAPHQL_URL, REST_REPO_URL, TEST_BASE_URL } from "../../support/e2e";

context("Listing and adding repositories", () => {
beforeEach(() => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.intercept('POST', GRAPHQL_URL).as("getRepos");

// cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.get("[data-cy=addRepo]").click();
Expand All @@ -32,7 +32,7 @@ context("Listing and adding repositories", () => {

// confirm repo adding dialog
cy.get("[data-cy=addRepoDialog]").click();
cy.intercept("GET", "**/repos/**").as("showRepos");
cy.intercept("GET", REST_REPO_URL).as("showRepos");
cy.wait("@showRepos", { timeout: 15000 });

// check if the correct number of repos was added
Expand Down
7 changes: 3 additions & 4 deletions cypress/e2e/adrManagerTest/DeleteAdr.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_BASE_URL } from "../../support/e2e";
import { GRAPHQL_URL, REST_REPO_URL, TEST_BASE_URL } from "../../support/e2e";

context("Deleting an ADR from a repo", () => {
it("Remove one ADR", () => {
Expand All @@ -9,14 +9,13 @@ context("Deleting an ADR from a repo", () => {
cy.visit(TEST_BASE_URL);

// add the ADR-Manager repo
// cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.intercept('POST', GRAPHQL_URL).as("getRepos");
cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=listRepo]").contains("ADR-Manager").click();
cy.get("[data-cy=addRepoDialog]").click();
// cy.intercept('POST', 'https://api.github.com/graphql').as("showRepos");
cy.intercept("GET", "**/repos/**").as("showRepos");
cy.intercept("GET", REST_REPO_URL).as("showRepos");

cy.wait("@showRepos", { timeout: 10000 });

Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/adrManagerTest/DeleteRepo.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_BASE_URL } from "../../support/e2e";
import { TEST_BASE_URL, GRAPHQL_URL } from "../../support/e2e";

context("Deleting repositories", () => {
it("Remove a repo", () => {
Expand All @@ -10,7 +10,7 @@ context("Deleting repositories", () => {

// add ADR Manager repo
// cy.intercept("GET", "**/user/repos**").as("getRepos");
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.intercept('POST', GRAPHQL_URL).as("getRepos");

cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/adrManagerTest/Modes.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_BASE_URL } from "../../support/e2e";
import { GRAPHQL_URL, TEST_BASE_URL } from "../../support/e2e";

context("Using editor modes", () => {
it("Switch to professional mode and create a new ADR", () => {
Expand All @@ -9,7 +9,7 @@ context("Using editor modes", () => {
cy.visit(TEST_BASE_URL);

// add ADR Manager repo
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.intercept('POST', GRAPHQL_URL).as("getRepos");

cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/adrManagerTest/Parser.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TEST_BASE_URL } from "../../support/e2e";
import { GRAPHQL_URL, TEST_BASE_URL } from "../../support/e2e";

context("Using Markdown modes", () => {
it("Convert raw Markdown", () => {
Expand All @@ -9,7 +9,7 @@ context("Using Markdown modes", () => {
cy.visit(TEST_BASE_URL);

// add ADR Manager repo
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.intercept('POST', GRAPHQL_URL).as("getRepos");
cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=listRepo]").contains("ADR-Manager").click();
Expand Down
15 changes: 7 additions & 8 deletions cypress/e2e/adrManagerTest/PushNewAdr.cy.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { TEST_BASE_URL } from "../../support/e2e";
import { GRAPHQL_URL, REST_BRANCH_URL, REST_COMMIT_URL, TEST_BASE_URL } from "../../support/e2e";

context("Committing, pushing, and remote-deleting an ADR", () => {
it("Commit and push new ADR, then delete from GitHub", () => {
const REPO_NAME = "adr/adr";
const BRANCH_NAME = "gh-pages";
const REPO_NAME = "adr/adr-test-repository-empty";
const BRANCH_NAME = "testing-branch";

function addRepositoryAndSwitchBranch() {
// add the ADR-Manager repo
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");

cy.intercept("POST", GRAPHQL_URL).as("getRepos");
cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
cy.get("[data-cy=search-field-for-adding-repository]").type(REPO_NAME);
Expand All @@ -32,6 +30,7 @@ context("Committing, pushing, and remote-deleting an ADR", () => {
cy.wait(2000);
}


window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
window.localStorage.setItem("user", Cypress.env("USER"))
Expand Down Expand Up @@ -60,8 +59,8 @@ context("Committing, pushing, and remote-deleting an ADR", () => {
// push to GitHub
cy.get("[data-cy=btnOfDialogCommitForPush]").click();

cy.intercept("GET", "**/repos/**/branches/**").as("getCommitSha");
cy.intercept("POST", "**/repos/**/git/commits?**").as("commitRequest");
cy.intercept("GET", REST_BRANCH_URL).as("getCommitSha");
cy.intercept("POST", REST_COMMIT_URL).as("commitRequest");

// cy.wait("@getCommitSha");
// cy.wait("@commitRequest")
Expand Down
5 changes: 2 additions & 3 deletions cypress/e2e/adrManagerTest/Routing.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TEST_BASE_URL } from "../../support/e2e";

import { GRAPHQL_URL, TEST_BASE_URL } from "../../support/e2e";
context("Routing and correct URLs", () => {
beforeEach(() => {
window.localStorage.clear();
Expand All @@ -12,7 +11,7 @@ context("Routing and correct URLs", () => {
cy.url().should("equal", TEST_BASE_URL);

// add the ADR-Manager repo
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
cy.intercept('POST', GRAPHQL_URL).as("getRepos");

cy.get("[data-cy=addRepo]").click();
cy.wait("@getRepos").its("response.statusCode").should("eq", 200);
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/adrManagerTest/apiUrlConfig/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const GRAPHQL_URL = "https://api.github.com/graphql"
export const REST_REPO_URL = "**/repos/**"
export const REST_BRANCH_URL = "**/repos/**/branches/**"
export const REST_COMMIT_URL = "**/repos/**/git/commits?**"
4 changes: 4 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ import "./commands";
import "@cypress/code-coverage/support";

export const TEST_BASE_URL = "http://localhost:8000/adr-manager/#/manager";
export const GRAPHQL_URL = "https://api.github.com/graphql"
export const REST_REPO_URL = "**/repos/**"
export const REST_BRANCH_URL = "**/repos/**/branches/**"
export const REST_COMMIT_URL = "**/repos/**/git/commits?**"
2 changes: 1 addition & 1 deletion docs/evaluation/adr-parsing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ An automatic test checking whether an ADR can be parsed was implemented.

```[JavaScript]
{
"PIZZLY_E2E_AUTH_ID": "abcdefg-123456"
"OAUTH_E2E_AUTH_ID": "abcdefg-123456"
}
```

Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default {
moduleNameMapper: {
vue$: "vue/dist/vue.common.js",
"^@/(.*)$": "<rootDir>/src/$1",
"pizzly-js": "<rootDir>/tests/pizzly-mock.js"
},
// The test environment that will be used for testing
testEnvironment: "node",
Expand Down
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
"format": "prettier --write . --ignore-unknown"
},
"dependencies": {
"@auth0/auth0-spa-js": "^2.1.2",
"@mdi/font": "^7.2.96",
"@octokit/rest": "^20.0.2",
"antlr4": "^4.13.0",
"axios": "^1.4.0",
"core-js": "^3.31.1",
"firebase": "^10.6.0",
"marked": "^5.1.1",
"pizzly-js": "^0.2.8",
"roboto-fontface": "*",
"sanitize-filename": "^1.6.3",
"splitpanes": "^2.4.1",
Expand Down
38 changes: 12 additions & 26 deletions src/components/ConnectToGitHubButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ export default {
}),
mounted() {
console.log("mounted");
},
destroyed() {
console.log("Bye from the git login github component!");
},
methods: {
hasAuthId() {
if (localStorage.getItem("authId") === null) {
this.signInWithGithub()
} else {
Expand All @@ -35,34 +33,22 @@ export default {
});
}
},
//LOGIN WITH GITHUB
signInWithGithub: async function () {
GithubProvider.addScope('repo read:user gist workflow read:org')
return signInWithPopup(auth, GithubProvider)
.then((result) => {
const credential = GithubAuthProvider.credentialFromResult(result);
const token = credential.accessToken; //Token OAuth (JWT)
const user = result.user
localStorage.setItem("authId", token)
localStorage.setItem('user', user?.reloadUserInfo?.screenName)
// getGithubProfile(token).then(userProfile => console.log('Github Profile', userProfile))
// console.log('Authenticated User', user)
this.$router.push({
name: "Editor",
params: { id: this.user }
});
}).catch((error) => {
console.error('SignIn Error', error)
return signInWithPopup(auth, GithubProvider).then((result) => {
const credential = GithubAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const user = result.user
localStorage.setItem("authId", token)
localStorage.setItem('user', user?.reloadUserInfo?.screenName)
this.$router.push({
name: "Editor",
params: { id: this.user }
});
}).catch((error) => {
console.error('SignIn Error', error)
});
}
}
};
</script>
2 changes: 2 additions & 0 deletions src/components/DialogAddRepositories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ export default {
*/
addRepositories: async function () {
this.showLoadingOverlay = true;
debugger;
console.log(this.repositoriesSelected)
loadAllRepositoryContent(
this.repositoriesSelected.map((repo) => ({
fullName: repo.repoData.full_name,
Expand Down
11 changes: 0 additions & 11 deletions src/config.js

This file was deleted.

Loading

0 comments on commit 918b1e6

Please sign in to comment.