+
Sorry, no repositories were found!
-
+
{{ item.name }}
@@ -96,13 +68,8 @@
Repositories to be added
-
+
@@ -117,18 +84,11 @@
- {
- showDialog = false;
- addRepositories();
- }
- "
- >
+ {
+ showDialog = false;
+ addRepositories();
+ }
+ ">
Add Repositories
Cancel
@@ -207,9 +167,9 @@ export default {
/**
* Loads all (added and unadded) repositories the user is authorized to access into repositoriesCurrentPage.
*/
- loadRepositoryList() {
+ async loadRepositoryList() {
this.countLoadingPromises++;
- loadRepositoryList(this.searchText, this.page, this.perPage)
+ loadRepositoryList()
.then((res) => {
if (!Array.isArray(res)) {
throw "Could not load repository list.";
@@ -240,6 +200,7 @@ export default {
searchRepositoryList(this.searchText, this.perPage, this.repositoriesCurrentPage)
.then((repos) => {
console.log("Loaded Repos", repos);
+
if (!Array.isArray(repos)) {
throw "Could not search repository list.";
}
diff --git a/src/components/DialogCommit.vue b/src/components/DialogCommit.vue
index bcd7bb2..546f620 100644
--- a/src/components/DialogCommit.vue
+++ b/src/components/DialogCommit.vue
@@ -1,15 +1,9 @@
-
+
@@ -29,20 +23,12 @@
mdi-file Select files
-
+
mdi-check
-
+
mdi-alert-circle-outline
@@ -51,22 +37,17 @@
- mdi-plus
- New files
+ mdi-plus
+ New files
-
+
@@ -74,19 +55,16 @@
- mdi-file-document-edit Changed files
+ mdi-file-document-edit Changed
+ files
-
+
@@ -94,22 +72,17 @@
- mdi-delete
- Deleted files
+ mdi-delete
+ Deleted files
-
+
@@ -118,58 +91,36 @@
mdi-message-text Enter commit message
-
+
mdi-check
-
+
mdi-alert-circle-outline
-
+
mdi-information-outline
- Your selected files will be pushed to {{ repo }} on {{ branch }} branch.
+ Your selected files will be pushed to {{ repo }} on {{ branch }} branch.
- {
- handleCommitButtonAction();
- dialogVisible = false;
- $emit('commit');
- }
- "
- >
+ {
+ handleCommitButtonAction();
+ dialogVisible = false;
+ $emit('commit');
+ }
+ ">
Commit & Push
Cancel
@@ -179,7 +130,7 @@
-
+
\ No newline at end of file
diff --git a/src/plugins/api.js b/src/plugins/api.js
index 4fc6cf0..57afb02 100644
--- a/src/plugins/api.js
+++ b/src/plugins/api.js
@@ -29,11 +29,13 @@ export function setInfosForApi(currRepoOwner, currRepoName, currBranch) {
* @returns {Promise} the array of emails with attributes 'email', 'primary', 'verified', 'visibility'
*/
export async function getUserEmail() {
- return pizzly
- .integration("github")
- .auth(localStorage.getItem("authId"))
- .get("/user/public_emails")
- .then((response) => response.json())
+ return axios
+ .get("https://api.github.com/user/public_emails", {
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem("authId")}`
+ }
+ })
+ .then((response) => response.data)
.catch((err) => {
console.log(err);
});
@@ -46,11 +48,12 @@ export async function getUserEmail() {
* @returns {Promise} the array of informations with attributes 'login', 'name', etc.
*/
export async function getUserName() {
- return pizzly
- .integration("github")
- .auth(localStorage.getItem("authId"))
- .get("/user")
- .then((response) => response.json())
+ return axios.get("https://api.github.com/user", {
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem('authId')}`
+ }
+ })
+ .then((response) => response.data)
.catch((err) => {
console.log(err);
});
@@ -62,48 +65,18 @@ export async function getUserName() {
* An example of the returned JSON structure can be found at 'https://docs.github.com/en/rest/reference/repos#get-a-branch'
* @returns {Promise} informations about the branch with attributes 'commit: { sha }', etc.
*/
-
export async function getCommitSha() {
- const token = localStorage.getItem('authId');
- const headers = {
- Authorization: `Bearer ${token}`,
- 'Content-Type': 'applicaion/json'
- }
- const body = {
- query: `query GetBranch{
- repository (name: "${repoName}", owner: "${repoOwner}") {
- ref (qualifiedName: "${branch}") {
- target {
- ... on Commit {
- history(first: 1) {
- nodes {
- oid
- }
- }
- }
- }
- }
- }
- }`
- }
- try {
- const response = await axios.post('https://api.github.com/graphql', body, { headers })
- if (!response.data) {
- return []
+ return axios.get("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/branches/" + branch, {
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem('authId')}`
}
- return {
- commit: {
- sha: response?.data?.data?.repository?.ref?.target?.history?.nodes?.[0]?.oid
- }
- }
- }
- catch (error) {
- return error.message
- }
-
+ })
+ .then((response) => response.data)
+ .catch((err) => {
+ console.log(err);
+ });
}
-
/**
* Returns a Promise with all informations about the newly created file.
*
@@ -112,16 +85,17 @@ export async function getCommitSha() {
* @returns {Promise} informations about the newly created file with attributes 'sha', etc.
*/
export async function createBlobs(file) {
- return pizzly
- .integration("github")
- .auth(localStorage.getItem("authId"))
- .post("/repos/" + repoOwner + "/" + repoName + "/git/blobs", {
- body: JSON.stringify({
- content: file,
- encoding: "utf-8"
- })
- })
- .then((response) => response.json())
+ return axios.post("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/git/blobs",
+ ({
+ content: file,
+ encoding: "utf-8"
+ }), {
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem('authId')}`,
+ Accept: "application / vnd.github + json"
+ }
+ })
+ .then((response) => response.data)
.then((body) => body)
.catch((err) => {
console.log(err);
@@ -137,16 +111,16 @@ export async function createBlobs(file) {
* @returns {Promise} informations about the newly created tree with attributes 'sha', etc.
*/
export async function createFileTree(lastCommitSha, folderTree) {
- return pizzly
- .integration("github")
- .auth(localStorage.getItem("authId"))
- .post("/repos/" + repoOwner + "/" + repoName + "/git/trees", {
- body: JSON.stringify({
- base_tree: lastCommitSha,
- tree: folderTree
- })
- })
- .then((response) => response.json())
+ return axios.post("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/git/trees", {
+ base_tree: lastCommitSha,
+ tree: folderTree
+
+ }, {
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem('authId')}`
+ }
+ })
+ .then((response) => response.data)
.then((body) => body)
.catch((err) => {
console.log(err);
@@ -164,18 +138,18 @@ export async function createFileTree(lastCommitSha, folderTree) {
* @returns {Promise} informations about the created commit with attributes 'sha', etc.
*/
export async function createCommit(commitMessage, authorInfos, lastCommitSha, treeSha) {
- return pizzly
- .integration("github")
- .auth(localStorage.getItem("authId"))
- .post("/repos/" + repoOwner + "/" + repoName + "/git/commits", {
- body: JSON.stringify({
- message: commitMessage,
- author: authorInfos,
- parents: [lastCommitSha],
- tree: treeSha
- })
- })
- .then((response) => response.json())
+ return axios.post("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/git/commits", {
+ message: commitMessage,
+ author: authorInfos,
+ parents: [lastCommitSha],
+ tree: treeSha
+
+ }, {
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem('authId')}`
+ }
+ })
+ .then((response) => response.data)
.then((body) => body)
.catch((err) => {
console.log(err);
@@ -189,81 +163,23 @@ export async function createCommit(commitMessage, authorInfos, lastCommitSha, tr
* @param {string} newCommitSha - the commit sha of the newly created commit
* @returns {Promise} informations about the reference.
*/
-export async function pushToGitHub(newCommitSha, commitFiles, commitMessgae) {
- let countKeysList = commitFiles.length;
- let countForEach = 0;
-
- if (commitFiles.length > 0) {
- try {
- let additions = commitFiles.map((file) => {
- return {
- path: file.path,
- contents: btoa(file.value)
- }
- })
- let deletions = commitFiles.map((file) => {
- return {
- path: file.path,
- }
- })
- let fileChanges = {
- additions,
- // deletions
- }
- const headers = {
- Authorization: `Bearer ${localStorage.getItem('authId')}`
- }
- const mutationQuery = `
- mutation createCommit(
- $fileChanges: FileChanges,
- $oid: GitObjectID!,
- $branch: String,
- $commitMessage: String!)
- {
- createCommitOnBranch(input: {
- branch: {
- repositoryNameWithOwner: "${repoOwner}/${repoName}"
- branchName: $branch
- }
- message: {
- headline: $commitMessage
- }
- fileChanges: $fileChanges
- expectedHeadOid: $oid
- }) {
- commit {
- commitUrl
- }
- }
- }`;
-
- const variables = {
- fileChanges: fileChanges,
- oid: newCommitSha,
- branch: branch,
- commitMessage: commitMessgae,
- };
-
- const response = await axios.post(
- 'https://api.github.com/graphql',
- { query: mutationQuery, variables: variables },
- { headers: headers }
- );
-
- if (!resp.data) {
- return []
- }
- debugger
- return resp.data.data;
-
-
- } catch (error) {
- console.log(error.message)
+export async function pushToGitHub(newCommitSha) {
+ return axios.post("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/git/refs/heads/" + branch, {
+ ref: "refs/heads/" + branch,
+ sha: newCommitSha
+ }, {
+ headers: {
+ Authorization: `Bearer ${localStorage.getItem('authId')}`
}
- }
+ })
+ .then((response) => response.data)
+ .then((body) => body)
+ .catch((err) => {
+ console.log(err);
+ });
+}
-}
/**
* Returns a Promise with the list of repositories accessible by the user.
@@ -289,7 +205,7 @@ export async function loadRepositoryList(searchText = "", page = 1, perPage = 5)
const body = {
query: `query {
user(login: "${userId}") {
- repositories(first: ${perPage}, after: null, orderBy: { field: UPDATED_AT, direction: DESC }) {
+ repositories(first: ${perPage}, after: null,orderBy: { field: UPDATED_AT, direction: DESC }) {
nodes {
id
resourcePath
@@ -376,44 +292,19 @@ export async function searchRepositoryList(searchString, maxResults = 2, searchR
*/
export async function loadFileTreeOfRepository(repoFullName, branch) {
- const token = localStorage.getItem("authId")
- try {
- const headers = {
- Authorization: `Bearer ${token}`,
- 'Content-Type': 'application/json',
- }
- const userId = localStorage.getItem('user')
-
- const body = {
- query: `query {
- repository(owner:"${userId}", name:"${repoFullName.split("/")[1]}") {
- object(expression: "HEAD:") {
- ... on Tree {
- entries {
- name
- type
- mode
- path
- }
- }
- }
- }
- }`
- }
- const response = await axios.post('https://api.github.com/graphql', body, { headers })
- if (!response.data) {
- return []
+ let user = localStorage.getItem("authId");
+ return axios.get("https://api.github.com/repos/" + repoFullName + "/git/trees/" + branch + "?recursive=1", {
+ headers: {
+ Authorization: `Bearer ${user}`
}
-
- return { tree: response.data.data.repository.object.entries }
- }
- catch (error) {
- return error.message
- }
-
-
+ })
+ .then((response) => response.data)
+ .catch((err) => {
+ console.log(err);
+ });
}
+
/**Returns a list of the names of all branches of the repository.
*
* An example call is 'https://api.github.com/repos/adr/madr/branches'
@@ -424,12 +315,13 @@ export async function loadFileTreeOfRepository(repoFullName, branch) {
*/
export async function loadBranchesName(repoName, username) {
let dataAuth = localStorage.getItem("authId");
-
- return pizzly
- .integration("github")
- .auth(dataAuth)
- .get("/repos/" + username + "/" + repoName + "/branches?per_page=999")
- .then((response) => response.json())
+ return axios
+ .get("https://api.github.com/repos/" + username + "/" + repoName + "/branches?per_page=999", {
+ headers: {
+ Authorization: `Bearer ${dataAuth}`
+ }
+ })
+ .then((response) => response.data)
.catch((err) => {
console.log(err);
});
@@ -457,11 +349,13 @@ export async function loadRawFile(repoFullName, branch, filePath) {
filePath
);
} else {
- return pizzly
- .integration("github")
- .auth(user)
- .get("/repos/" + repoFullName + "/contents/" + filePath + "?ref=" + branch)
- .then((response) => response.json())
+ return axios
+ .get("https://api.github.com/repos/" + repoFullName + "/contents/" + filePath + "?ref=" + branch, {
+ headers: {
+ Authorization: `Bearer ${user}`
+ }
+ })
+ .then((response) => response.data)
.then((response) => decodeUnicode(response.content))
.catch((err) => {
console.log(err);
From 1d6eab7f1e22d9729605767c9aea91ec0a42717c Mon Sep 17 00:00:00 2001
From: Moneeza Syed <14besemsyed@seecs.edu.pk>
Date: Thu, 23 Nov 2023 12:10:15 +0100
Subject: [PATCH 04/19] added user secret
---
.github/workflows/tests.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 6d6b936..78961f4 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -38,6 +38,7 @@ jobs:
- name: Run Cypress tests
env:
CYPRESS_OAUTH_E2E_AUTH_ID: ${{ secrets.OAUTH_E2E_AUTH_ID }}
+ user: ${{ secrets.user }}
run: |
npm start &
npm run e2e:test-ci
From eeddfba45ecb22137663a7efabfb5e2f55fc105e Mon Sep 17 00:00:00 2001
From: Moneeza Syed <14besemsyed@seecs.edu.pk>
Date: Thu, 23 Nov 2023 12:14:07 +0100
Subject: [PATCH 05/19] replaced secrets in cypress
---
.github/workflows/tests.yml | 2 +-
cypress/e2e/adrManagerTest/AddNewAdr.cy.js | 2 +-
cypress/e2e/adrManagerTest/AddRepo.cy.js | 2 +-
cypress/e2e/adrManagerTest/DeleteAdr.cy.js | 2 +-
cypress/e2e/adrManagerTest/DeleteRepo.cy.js | 2 +-
cypress/e2e/adrManagerTest/Modes.cy.js | 2 +-
cypress/e2e/adrManagerTest/Parser.cy.js | 2 +-
cypress/e2e/adrManagerTest/PushNewAdr.cy.js | 2 +-
cypress/e2e/adrManagerTest/Routing.cy.js | 2 +-
9 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 78961f4..9beaeda 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -38,7 +38,7 @@ jobs:
- name: Run Cypress tests
env:
CYPRESS_OAUTH_E2E_AUTH_ID: ${{ secrets.OAUTH_E2E_AUTH_ID }}
- user: ${{ secrets.user }}
+ user: ${{ secrets.USER }}
run: |
npm start &
npm run e2e:test-ci
diff --git a/cypress/e2e/adrManagerTest/AddNewAdr.cy.js b/cypress/e2e/adrManagerTest/AddNewAdr.cy.js
index 6adf38a..b61ded9 100644
--- a/cypress/e2e/adrManagerTest/AddNewAdr.cy.js
+++ b/cypress/e2e/adrManagerTest/AddNewAdr.cy.js
@@ -4,7 +4,7 @@ context("Adding a new ADR to a repo", () => {
it("Create a new ADR", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
- window.localStorage.setItem("user", Cypress.env("user"))
+ window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
// add the ADR-Manager repo
diff --git a/cypress/e2e/adrManagerTest/AddRepo.cy.js b/cypress/e2e/adrManagerTest/AddRepo.cy.js
index 3852b0f..fb0eac6 100644
--- a/cypress/e2e/adrManagerTest/AddRepo.cy.js
+++ b/cypress/e2e/adrManagerTest/AddRepo.cy.js
@@ -4,7 +4,7 @@ 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"))
+ window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
cy.intercept('POST', 'https://api.github.com/graphql').as("getRepos");
diff --git a/cypress/e2e/adrManagerTest/DeleteAdr.cy.js b/cypress/e2e/adrManagerTest/DeleteAdr.cy.js
index 505b32b..17eb3b0 100644
--- a/cypress/e2e/adrManagerTest/DeleteAdr.cy.js
+++ b/cypress/e2e/adrManagerTest/DeleteAdr.cy.js
@@ -4,7 +4,7 @@ context("Deleting an ADR from a repo", () => {
it("Remove one ADR", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
- window.localStorage.setItem("user", Cypress.env("user"))
+ window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
diff --git a/cypress/e2e/adrManagerTest/DeleteRepo.cy.js b/cypress/e2e/adrManagerTest/DeleteRepo.cy.js
index 0dbc04b..ab22b3d 100644
--- a/cypress/e2e/adrManagerTest/DeleteRepo.cy.js
+++ b/cypress/e2e/adrManagerTest/DeleteRepo.cy.js
@@ -4,7 +4,7 @@ context("Deleting repositories", () => {
it("Remove a repo", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
- window.localStorage.setItem("user", Cypress.env("user"))
+ window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
diff --git a/cypress/e2e/adrManagerTest/Modes.cy.js b/cypress/e2e/adrManagerTest/Modes.cy.js
index 1f8e195..dd8c089 100644
--- a/cypress/e2e/adrManagerTest/Modes.cy.js
+++ b/cypress/e2e/adrManagerTest/Modes.cy.js
@@ -4,7 +4,7 @@ context("Using editor modes", () => {
it("Switch to professional mode and create a new ADR", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
- window.localStorage.setItem("user", Cypress.env("user"))
+ window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
diff --git a/cypress/e2e/adrManagerTest/Parser.cy.js b/cypress/e2e/adrManagerTest/Parser.cy.js
index 0111ca0..ef8abfe 100644
--- a/cypress/e2e/adrManagerTest/Parser.cy.js
+++ b/cypress/e2e/adrManagerTest/Parser.cy.js
@@ -4,7 +4,7 @@ context("Using Markdown modes", () => {
it("Convert raw Markdown", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
- window.localStorage.setItem("user", Cypress.env("user"))
+ window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
diff --git a/cypress/e2e/adrManagerTest/PushNewAdr.cy.js b/cypress/e2e/adrManagerTest/PushNewAdr.cy.js
index fd7b640..c592f32 100644
--- a/cypress/e2e/adrManagerTest/PushNewAdr.cy.js
+++ b/cypress/e2e/adrManagerTest/PushNewAdr.cy.js
@@ -34,7 +34,7 @@ context("Committing, pushing, and remote-deleting an ADR", () => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
- window.localStorage.setItem("user", Cypress.env("user"))
+ window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
addRepositoryAndSwitchBranch();
diff --git a/cypress/e2e/adrManagerTest/Routing.cy.js b/cypress/e2e/adrManagerTest/Routing.cy.js
index 71d4c6a..63821c6 100644
--- a/cypress/e2e/adrManagerTest/Routing.cy.js
+++ b/cypress/e2e/adrManagerTest/Routing.cy.js
@@ -4,7 +4,7 @@ context("Routing and correct URLs", () => {
beforeEach(() => {
window.localStorage.clear();
window.localStorage.setItem("authId", Cypress.env("OAUTH_E2E_AUTH_ID"));
- window.localStorage.setItem("user", Cypress.env("user"))
+ window.localStorage.setItem("user", Cypress.env("USER"))
cy.visit(TEST_BASE_URL);
});
From 3de5194c385f0f0f5dfaebe0282b01bd32795802 Mon Sep 17 00:00:00 2001
From: Moneeza Syed <14besemsyed@seecs.edu.pk>
Date: Thu, 23 Nov 2023 20:39:45 +0100
Subject: [PATCH 06/19] new changes in test
---
.github/workflows/tests.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 9beaeda..9dce60a 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -38,7 +38,7 @@ jobs:
- name: Run Cypress tests
env:
CYPRESS_OAUTH_E2E_AUTH_ID: ${{ secrets.OAUTH_E2E_AUTH_ID }}
- user: ${{ secrets.USER }}
+ USER: ${{ secrets.USER }}
run: |
npm start &
npm run e2e:test-ci
From 45217764bd09eb67afbd5377913a03ce34c45a02 Mon Sep 17 00:00:00 2001
From: Moneeza Syed <14besemsyed@seecs.edu.pk>
Date: Thu, 23 Nov 2023 20:57:39 +0100
Subject: [PATCH 07/19] new changes in test
---
.github/workflows/tests.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 9dce60a..9e00f4e 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -38,7 +38,7 @@ jobs:
- name: Run Cypress tests
env:
CYPRESS_OAUTH_E2E_AUTH_ID: ${{ secrets.OAUTH_E2E_AUTH_ID }}
- USER: ${{ secrets.USER }}
+ CYPRESS_USER: ${{ secrets.USER }}
run: |
npm start &
npm run e2e:test-ci
From 918b1e6654e156c53c0eb3aefec38374a46e903a Mon Sep 17 00:00:00 2001
From: Moneeza Syed <14besemsyed@seecs.edu.pk>
Date: Thu, 30 Nov 2023 16:01:38 +0100
Subject: [PATCH 08/19] fixed pizzly replacements
---
README.md | 26 ++--
cypress/e2e/adrManagerTest/AddNewAdr.cy.js | 4 +-
cypress/e2e/adrManagerTest/AddRepo.cy.js | 6 +-
cypress/e2e/adrManagerTest/DeleteAdr.cy.js | 7 +-
cypress/e2e/adrManagerTest/DeleteRepo.cy.js | 4 +-
cypress/e2e/adrManagerTest/Modes.cy.js | 4 +-
cypress/e2e/adrManagerTest/Parser.cy.js | 4 +-
cypress/e2e/adrManagerTest/PushNewAdr.cy.js | 15 +--
cypress/e2e/adrManagerTest/Routing.cy.js | 5 +-
.../e2e/adrManagerTest/apiUrlConfig/config.js | 4 +
cypress/support/e2e.js | 4 +
docs/evaluation/adr-parsing/README.md | 2 +-
jest.config.js | 1 -
package-lock.json | 8 +-
package.json | 3 -
src/components/ConnectToGitHubButton.vue | 38 ++----
src/components/DialogAddRepositories.vue | 2 +
src/config.js | 11 --
src/plugins/api.js | 124 ++++++------------
src/plugins/apiConfig/config.js | 9 ++
tests/pizzly-mock.js | 26 ----
21 files changed, 107 insertions(+), 200 deletions(-)
create mode 100644 cypress/e2e/adrManagerTest/apiUrlConfig/config.js
delete mode 100644 src/config.js
create mode 100644 src/plugins/apiConfig/config.js
delete mode 100644 tests/pizzly-mock.js
diff --git a/README.md b/README.md
index 709feb9..e68c9d4 100644
--- a/README.md
+++ b/README.md
@@ -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`).
@@ -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 .
-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
diff --git a/cypress/e2e/adrManagerTest/AddNewAdr.cy.js b/cypress/e2e/adrManagerTest/AddNewAdr.cy.js
index b61ded9..9b88227 100644
--- a/cypress/e2e/adrManagerTest/AddNewAdr.cy.js
+++ b/cypress/e2e/adrManagerTest/AddNewAdr.cy.js
@@ -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", () => {
@@ -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();
diff --git a/cypress/e2e/adrManagerTest/AddRepo.cy.js b/cypress/e2e/adrManagerTest/AddRepo.cy.js
index fb0eac6..0e2a576 100644
--- a/cypress/e2e/adrManagerTest/AddRepo.cy.js
+++ b/cypress/e2e/adrManagerTest/AddRepo.cy.js
@@ -1,4 +1,4 @@
-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(() => {
@@ -6,7 +6,7 @@ context("Listing and adding repositories", () => {
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();
@@ -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
diff --git a/cypress/e2e/adrManagerTest/DeleteAdr.cy.js b/cypress/e2e/adrManagerTest/DeleteAdr.cy.js
index 17eb3b0..a4ab0aa 100644
--- a/cypress/e2e/adrManagerTest/DeleteAdr.cy.js
+++ b/cypress/e2e/adrManagerTest/DeleteAdr.cy.js
@@ -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", () => {
@@ -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 });
diff --git a/cypress/e2e/adrManagerTest/DeleteRepo.cy.js b/cypress/e2e/adrManagerTest/DeleteRepo.cy.js
index ab22b3d..4377753 100644
--- a/cypress/e2e/adrManagerTest/DeleteRepo.cy.js
+++ b/cypress/e2e/adrManagerTest/DeleteRepo.cy.js
@@ -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", () => {
@@ -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);
diff --git a/cypress/e2e/adrManagerTest/Modes.cy.js b/cypress/e2e/adrManagerTest/Modes.cy.js
index dd8c089..8d24f20 100644
--- a/cypress/e2e/adrManagerTest/Modes.cy.js
+++ b/cypress/e2e/adrManagerTest/Modes.cy.js
@@ -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", () => {
@@ -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);
diff --git a/cypress/e2e/adrManagerTest/Parser.cy.js b/cypress/e2e/adrManagerTest/Parser.cy.js
index ef8abfe..df5eaaf 100644
--- a/cypress/e2e/adrManagerTest/Parser.cy.js
+++ b/cypress/e2e/adrManagerTest/Parser.cy.js
@@ -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", () => {
@@ -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();
diff --git a/cypress/e2e/adrManagerTest/PushNewAdr.cy.js b/cypress/e2e/adrManagerTest/PushNewAdr.cy.js
index c592f32..a9951ec 100644
--- a/cypress/e2e/adrManagerTest/PushNewAdr.cy.js
+++ b/cypress/e2e/adrManagerTest/PushNewAdr.cy.js
@@ -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);
@@ -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"))
@@ -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")
diff --git a/cypress/e2e/adrManagerTest/Routing.cy.js b/cypress/e2e/adrManagerTest/Routing.cy.js
index 63821c6..c1ea15f 100644
--- a/cypress/e2e/adrManagerTest/Routing.cy.js
+++ b/cypress/e2e/adrManagerTest/Routing.cy.js
@@ -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();
@@ -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);
diff --git a/cypress/e2e/adrManagerTest/apiUrlConfig/config.js b/cypress/e2e/adrManagerTest/apiUrlConfig/config.js
new file mode 100644
index 0000000..2c43e90
--- /dev/null
+++ b/cypress/e2e/adrManagerTest/apiUrlConfig/config.js
@@ -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?**"
diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js
index 5e55463..fac9c1f 100644
--- a/cypress/support/e2e.js
+++ b/cypress/support/e2e.js
@@ -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?**"
diff --git a/docs/evaluation/adr-parsing/README.md b/docs/evaluation/adr-parsing/README.md
index a8e863a..819ea66 100644
--- a/docs/evaluation/adr-parsing/README.md
+++ b/docs/evaluation/adr-parsing/README.md
@@ -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"
}
```
diff --git a/jest.config.js b/jest.config.js
index 31e5dec..eeab853 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -21,7 +21,6 @@ export default {
moduleNameMapper: {
vue$: "vue/dist/vue.common.js",
"^@/(.*)$": "/src/$1",
- "pizzly-js": "/tests/pizzly-mock.js"
},
// The test environment that will be used for testing
testEnvironment: "node",
diff --git a/package-lock.json b/package-lock.json
index 80e0fa1..4247294 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -16,7 +16,6 @@
"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",
@@ -10507,12 +10506,7 @@
"node": ">= 6"
}
},
- "node_modules/pizzly-js": {
- "version": "0.2.8",
- "resolved": "https://registry.npmjs.org/pizzly-js/-/pizzly-js-0.2.8.tgz",
- "integrity": "sha512-770xh/dunk7034B5C0EZChRd9gIhhrDTvol5rt0EspM5Ny69kaluenjoh+jbu9HNJUZw019Iayqh9vTpItAFGA==",
- "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."
- },
+
"node_modules/pkg-dir": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz",
diff --git a/package.json b/package.json
index 1938c1b..af909cf 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/components/ConnectToGitHubButton.vue b/src/components/ConnectToGitHubButton.vue
index 5935b7a..9e3d5e2 100644
--- a/src/components/ConnectToGitHubButton.vue
+++ b/src/components/ConnectToGitHubButton.vue
@@ -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 {
@@ -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)
+ });
}
-
}
};
diff --git a/src/components/DialogAddRepositories.vue b/src/components/DialogAddRepositories.vue
index 911877e..844b782 100644
--- a/src/components/DialogAddRepositories.vue
+++ b/src/components/DialogAddRepositories.vue
@@ -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,
diff --git a/src/config.js b/src/config.js
deleted file mode 100644
index 5eff55f..0000000
--- a/src/config.js
+++ /dev/null
@@ -1,11 +0,0 @@
-const config = {
- // pizzlyHost: "https://adr-manager-auth.herokuapp.com/",
- // pizzlyPublishableKey: "Ksd2lsdkm-1liI7CqX2,3;NJ9cyWvpKf5",
- // domain: "adr-manager.eu.auth0.com",
- // clientId: "G62KNFzCRTXMmKDPR4Kc8q1f4F4lgqOx",
- // redirectUri: "http://localhost:8000/adr-manager/#/",
- // authorizationParams: "scope=repo",
-
-};
-
-export default config;
diff --git a/src/plugins/api.js b/src/plugins/api.js
index 57afb02..e73372c 100644
--- a/src/plugins/api.js
+++ b/src/plugins/api.js
@@ -1,16 +1,8 @@
/* This file contains any calls to the backend. */
-import Pizzly from "pizzly-js";
import { Repository } from "./classes.js";
-import config from "../config";
import axios from "axios"
-
-// API-Calls (functions return promises)
-// A pizzy-object to make request to github
-let pizzly = new Pizzly({
- host: config.pizzlyHost,
- publishableKey: config.pizzlyPublishableKey
-});
+import { BASE_URL_REPO, BASE_URL_USER, HEADERS } from "./apiConfig/config.js"
let repoOwner = "";
let repoName = "";
@@ -29,12 +21,9 @@ export function setInfosForApi(currRepoOwner, currRepoName, currBranch) {
* @returns {Promise} the array of emails with attributes 'email', 'primary', 'verified', 'visibility'
*/
export async function getUserEmail() {
+ const headers = HEADERS;
return axios
- .get("https://api.github.com/user/public_emails", {
- headers: {
- Authorization: `Bearer ${localStorage.getItem("authId")}`
- }
- })
+ .get(`${BASE_URL_USER}/public_emails`, { headers })
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -48,11 +37,8 @@ export async function getUserEmail() {
* @returns {Promise} the array of informations with attributes 'login', 'name', etc.
*/
export async function getUserName() {
- return axios.get("https://api.github.com/user", {
- headers: {
- Authorization: `Bearer ${localStorage.getItem('authId')}`
- }
- })
+ const headers = HEADERS
+ return axios.get(BASE_URL_USER, { headers })
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -66,11 +52,8 @@ export async function getUserName() {
* @returns {Promise} informations about the branch with attributes 'commit: { sha }', etc.
*/
export async function getCommitSha() {
- return axios.get("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/branches/" + branch, {
- headers: {
- Authorization: `Bearer ${localStorage.getItem('authId')}`
- }
- })
+ const headers = HEADERS
+ return axios.get(`${BASE_URL_REPO}/${repoOwner}/${repoName}/branches/${branch}`, { headers })
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -85,16 +68,14 @@ export async function getCommitSha() {
* @returns {Promise} informations about the newly created file with attributes 'sha', etc.
*/
export async function createBlobs(file) {
- return axios.post("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/git/blobs",
+ const headers = HEADERS;
+ const copyHeader = { ...headers }; // Spread syntax to create a shallow copy
+ copyHeader["Accept"] = "application/vnd.github+json";
+ return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/blobs`,
({
content: file,
encoding: "utf-8"
- }), {
- headers: {
- Authorization: `Bearer ${localStorage.getItem('authId')}`,
- Accept: "application / vnd.github + json"
- }
- })
+ }), { headers: copyHeader })
.then((response) => response.data)
.then((body) => body)
.catch((err) => {
@@ -111,15 +92,12 @@ export async function createBlobs(file) {
* @returns {Promise} informations about the newly created tree with attributes 'sha', etc.
*/
export async function createFileTree(lastCommitSha, folderTree) {
- return axios.post("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/git/trees", {
+ const headers = HEADERS
+ return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/trees`, {
base_tree: lastCommitSha,
tree: folderTree
- }, {
- headers: {
- Authorization: `Bearer ${localStorage.getItem('authId')}`
- }
- })
+ }, { headers })
.then((response) => response.data)
.then((body) => body)
.catch((err) => {
@@ -138,17 +116,14 @@ export async function createFileTree(lastCommitSha, folderTree) {
* @returns {Promise} informations about the created commit with attributes 'sha', etc.
*/
export async function createCommit(commitMessage, authorInfos, lastCommitSha, treeSha) {
- return axios.post("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/git/commits", {
+ const headers = HEADERS
+ return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/commits`, {
message: commitMessage,
author: authorInfos,
parents: [lastCommitSha],
tree: treeSha
- }, {
- headers: {
- Authorization: `Bearer ${localStorage.getItem('authId')}`
- }
- })
+ }, { headers })
.then((response) => response.data)
.then((body) => body)
.catch((err) => {
@@ -164,14 +139,11 @@ export async function createCommit(commitMessage, authorInfos, lastCommitSha, tr
* @returns {Promise} informations about the reference.
*/
export async function pushToGitHub(newCommitSha) {
- return axios.post("https://api.github.com/repos/" + repoOwner + "/" + repoName + "/git/refs/heads/" + branch, {
+ const headers = HEADERS
+ return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/refs/heads/${branch}`, {
ref: "refs/heads/" + branch,
sha: newCommitSha
- }, {
- headers: {
- Authorization: `Bearer ${localStorage.getItem('authId')}`
- }
- })
+ }, { headers })
.then((response) => response.data)
.then((body) => body)
.catch((err) => {
@@ -195,29 +167,25 @@ export async function loadRepositoryList(searchText = "", page = 1, perPage = 5)
const token = localStorage.getItem("authId");
try {
- const headers = {
- Authorization: `Bearer ${token}`,
- 'Content-Type': 'application/json',
- };
-
+ const headers = HEADERS
const userId = localStorage.getItem('user');
const body = {
query: `query {
- user(login: "${userId}") {
- repositories(first: ${perPage}, after: null,orderBy: { field: UPDATED_AT, direction: DESC }) {
+ user(login: "${userId}") {
+ repositories(first: ${perPage}, after: null, orderBy: { field: UPDATED_AT, direction: DESC }) {
nodes {
- id
- resourcePath
- updatedAt
- description
+ id
+ resourcePath
+ updatedAt
+ description
defaultBranchRef {
- name
- }
+ name
+ }
}
- }
}
- }`
+ }
+ }`
};
const response = await axios.post('https://api.github.com/graphql', body, { headers });
@@ -292,12 +260,9 @@ export async function searchRepositoryList(searchString, maxResults = 2, searchR
*/
export async function loadFileTreeOfRepository(repoFullName, branch) {
- let user = localStorage.getItem("authId");
- return axios.get("https://api.github.com/repos/" + repoFullName + "/git/trees/" + branch + "?recursive=1", {
- headers: {
- Authorization: `Bearer ${user}`
- }
- })
+ const headers = HEADERS
+
+ return axios.get(`${BASE_URL_REPO}/${repoFullName}/git/trees/${branch}?recursive=1`, { headers })
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -314,13 +279,9 @@ export async function loadFileTreeOfRepository(repoFullName, branch) {
* @returns {Promise<{ name : string }[]>} the fetched array of branches
*/
export async function loadBranchesName(repoName, username) {
- let dataAuth = localStorage.getItem("authId");
+ const headers = HEADERS
return axios
- .get("https://api.github.com/repos/" + username + "/" + repoName + "/branches?per_page=999", {
- headers: {
- Authorization: `Bearer ${dataAuth}`
- }
- })
+ .get(`${BASE_URL_REPO}/${username}/${repoName}/branches?per_page=999`, { headers })
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -338,7 +299,8 @@ export async function loadBranchesName(repoName, username) {
* @returns {Promise} a promise with the raw content of the specified file
*/
export async function loadRawFile(repoFullName, branch, filePath) {
- let user = localStorage.getItem("authId");
+ const headers = HEADERS
+
if (typeof branch !== "string" || typeof branch != "string") {
console.log(
"Invalid values for loadContentsForRepository. Given Repository full name: " +
@@ -350,10 +312,8 @@ export async function loadRawFile(repoFullName, branch, filePath) {
);
} else {
return axios
- .get("https://api.github.com/repos/" + repoFullName + "/contents/" + filePath + "?ref=" + branch, {
- headers: {
- Authorization: `Bearer ${user}`
- }
+ .get(`${BASE_URL_REPO}/${repoFullName}/contents/${filePath}?ref=${branch}`, {
+ headers
})
.then((response) => response.data)
.then((response) => decodeUnicode(response.content))
@@ -464,7 +424,7 @@ export async function loadARepositoryContent(repoFullName, branchName) {
};
repoObject.adrs.push(adrObject);
adrPromises.push(
- loadRawFile(repoFullName, branchName, adr.path, user, pizzly).then((rawMd) => {
+ loadRawFile(repoFullName, branchName, adr.path, user).then((rawMd) => {
adrObject.originalMd = rawMd;
adrObject.editedMd = rawMd;
})
diff --git a/src/plugins/apiConfig/config.js b/src/plugins/apiConfig/config.js
new file mode 100644
index 0000000..c946226
--- /dev/null
+++ b/src/plugins/apiConfig/config.js
@@ -0,0 +1,9 @@
+const BASE_URL_USER = "https://api.github.com/user"
+const BASE_URL_REPO = "https://api.github.com/repos"
+const HEADERS = {
+ Authorization: `Bearer ${localStorage.getItem("authId")
+ }`
+}
+
+
+export { BASE_URL_REPO, BASE_URL_USER, HEADERS }
diff --git a/tests/pizzly-mock.js b/tests/pizzly-mock.js
deleted file mode 100644
index 76e8f27..0000000
--- a/tests/pizzly-mock.js
+++ /dev/null
@@ -1,26 +0,0 @@
-import { repositories } from "./constants.js";
-module.exports = class Pizzly {
- constructor() {}
- integration(integration) {
- if (integration === "github") {
- return {
- auth() {
- return {
- async get(endpoint) {
- if (endpoint.startsWith("/user/repos")) {
- let query = endpoint.split("?").pop();
- let per_page = query.split("&per_page=")[1].split("&")[0];
- let page = query.split("&page=")[1].split("&")[0];
- return {
- json() {
- return repositories.slice((page - 1) * per_page, page * per_page);
- }
- };
- }
- }
- };
- }
- };
- }
- }
-};
From be65909bc27819ebd7b43b3eec9b93b53a6c52eb Mon Sep 17 00:00:00 2001
From: Moneeza Syed <14besemsyed@seecs.edu.pk>
Date: Thu, 30 Nov 2023 17:02:21 +0100
Subject: [PATCH 09/19] tests fixed
---
src/plugins/api.js | 28 +++++++++++++-------------
src/plugins/apiConfig/config.js | 10 +++++----
tests/api-searchRepositoryList.test.js | 2 ++
3 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/src/plugins/api.js b/src/plugins/api.js
index e73372c..0267b29 100644
--- a/src/plugins/api.js
+++ b/src/plugins/api.js
@@ -2,7 +2,7 @@
import { Repository } from "./classes.js";
import axios from "axios"
-import { BASE_URL_REPO, BASE_URL_USER, HEADERS } from "./apiConfig/config.js"
+import { BASE_URL_REPO, BASE_URL_USER, getHeaders } from "./apiConfig/config.js"
let repoOwner = "";
let repoName = "";
@@ -21,7 +21,7 @@ export function setInfosForApi(currRepoOwner, currRepoName, currBranch) {
* @returns {Promise} the array of emails with attributes 'email', 'primary', 'verified', 'visibility'
*/
export async function getUserEmail() {
- const headers = HEADERS;
+ const headers = getHeaders();
return axios
.get(`${BASE_URL_USER}/public_emails`, { headers })
.then((response) => response.data)
@@ -37,7 +37,7 @@ export async function getUserEmail() {
* @returns {Promise} the array of informations with attributes 'login', 'name', etc.
*/
export async function getUserName() {
- const headers = HEADERS
+ const headers = getHeaders()
return axios.get(BASE_URL_USER, { headers })
.then((response) => response.data)
.catch((err) => {
@@ -52,7 +52,7 @@ export async function getUserName() {
* @returns {Promise} informations about the branch with attributes 'commit: { sha }', etc.
*/
export async function getCommitSha() {
- const headers = HEADERS
+ const headers = getHeaders()
return axios.get(`${BASE_URL_REPO}/${repoOwner}/${repoName}/branches/${branch}`, { headers })
.then((response) => response.data)
.catch((err) => {
@@ -68,7 +68,7 @@ export async function getCommitSha() {
* @returns {Promise} informations about the newly created file with attributes 'sha', etc.
*/
export async function createBlobs(file) {
- const headers = HEADERS;
+ const headers = getHeaders();
const copyHeader = { ...headers }; // Spread syntax to create a shallow copy
copyHeader["Accept"] = "application/vnd.github+json";
return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/blobs`,
@@ -92,7 +92,7 @@ export async function createBlobs(file) {
* @returns {Promise} informations about the newly created tree with attributes 'sha', etc.
*/
export async function createFileTree(lastCommitSha, folderTree) {
- const headers = HEADERS
+ const headers = getHeaders()
return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/trees`, {
base_tree: lastCommitSha,
tree: folderTree
@@ -116,7 +116,7 @@ export async function createFileTree(lastCommitSha, folderTree) {
* @returns {Promise} informations about the created commit with attributes 'sha', etc.
*/
export async function createCommit(commitMessage, authorInfos, lastCommitSha, treeSha) {
- const headers = HEADERS
+ const headers = getHeaders()
return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/commits`, {
message: commitMessage,
author: authorInfos,
@@ -139,7 +139,7 @@ export async function createCommit(commitMessage, authorInfos, lastCommitSha, tr
* @returns {Promise} informations about the reference.
*/
export async function pushToGitHub(newCommitSha) {
- const headers = HEADERS
+ const headers = getHeaders()
return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/refs/heads/${branch}`, {
ref: "refs/heads/" + branch,
sha: newCommitSha
@@ -164,10 +164,8 @@ export async function pushToGitHub(newCommitSha) {
*/
export async function loadRepositoryList(searchText = "", page = 1, perPage = 5) {
- const token = localStorage.getItem("authId");
try {
- const headers = HEADERS
const userId = localStorage.getItem('user');
const body = {
@@ -188,7 +186,9 @@ export async function loadRepositoryList(searchText = "", page = 1, perPage = 5)
}`
};
- const response = await axios.post('https://api.github.com/graphql', body, { headers });
+ const response = await axios.post('https://api.github.com/graphql', body, {
+ headers: getHeaders()
+ });
if (!response?.data) {
return [];
@@ -260,7 +260,7 @@ export async function searchRepositoryList(searchString, maxResults = 2, searchR
*/
export async function loadFileTreeOfRepository(repoFullName, branch) {
- const headers = HEADERS
+ const headers = getHeaders()
return axios.get(`${BASE_URL_REPO}/${repoFullName}/git/trees/${branch}?recursive=1`, { headers })
.then((response) => response.data)
@@ -279,7 +279,7 @@ export async function loadFileTreeOfRepository(repoFullName, branch) {
* @returns {Promise<{ name : string }[]>} the fetched array of branches
*/
export async function loadBranchesName(repoName, username) {
- const headers = HEADERS
+ const headers = getHeaders()
return axios
.get(`${BASE_URL_REPO}/${username}/${repoName}/branches?per_page=999`, { headers })
.then((response) => response.data)
@@ -299,7 +299,7 @@ export async function loadBranchesName(repoName, username) {
* @returns {Promise} a promise with the raw content of the specified file
*/
export async function loadRawFile(repoFullName, branch, filePath) {
- const headers = HEADERS
+ const headers = getHeaders()
if (typeof branch !== "string" || typeof branch != "string") {
console.log(
diff --git a/src/plugins/apiConfig/config.js b/src/plugins/apiConfig/config.js
index c946226..0587c79 100644
--- a/src/plugins/apiConfig/config.js
+++ b/src/plugins/apiConfig/config.js
@@ -1,9 +1,11 @@
const BASE_URL_USER = "https://api.github.com/user"
const BASE_URL_REPO = "https://api.github.com/repos"
-const HEADERS = {
- Authorization: `Bearer ${localStorage.getItem("authId")
- }`
+
+const getHeaders = () => {
+ return {
+ Authorization: `Bearer ${localStorage?.getItem("authId")}`
+ }
}
-export { BASE_URL_REPO, BASE_URL_USER, HEADERS }
+export { BASE_URL_REPO, BASE_URL_USER, getHeaders }
diff --git a/tests/api-searchRepositoryList.test.js b/tests/api-searchRepositoryList.test.js
index cb73c9f..8396b9e 100644
--- a/tests/api-searchRepositoryList.test.js
+++ b/tests/api-searchRepositoryList.test.js
@@ -7,6 +7,7 @@ global.localStorage = {
return "abc....";
}
};
+console.log("###### print local storage #######", localStorage.getItem("authId"))
import { searchRepositoryList } from "../src/plugins/api.js";
import { searchTermRepoPairs } from "./constants.js";
@@ -21,6 +22,7 @@ for (let i = 0; i < searchTermRepoPairs.length; i++) {
let expectedResult = searchTermRepoPairs[i].results;
test("Test Searching Repos with list in parameter. Searching for " + searchTerm, async () => {
+ console.log(localStorage.getItem("authId"))
let list = [];
axios.post.mockResolvedValue({
From 4f6fa481cff81ead5609688a4b2fe6152a05b701 Mon Sep 17 00:00:00 2001
From: Moneeza Syed <14besemsyed@seecs.edu.pk>
Date: Sat, 2 Dec 2023 20:19:14 +0100
Subject: [PATCH 10/19] fixed interceptor
---
src/components/DialogAddRepositories.vue | 1 -
src/components/DialogCommit.vue | 1 -
src/components/FileExplorer.vue | 1 -
src/plugins/api.js | 37 +++++++++---------------
4 files changed, 13 insertions(+), 27 deletions(-)
diff --git a/src/components/DialogAddRepositories.vue b/src/components/DialogAddRepositories.vue
index 844b782..321b6f1 100644
--- a/src/components/DialogAddRepositories.vue
+++ b/src/components/DialogAddRepositories.vue
@@ -268,7 +268,6 @@ export default {
*/
addRepositories: async function () {
this.showLoadingOverlay = true;
- debugger;
console.log(this.repositoriesSelected)
loadAllRepositoryContent(
this.repositoriesSelected.map((repo) => ({
diff --git a/src/components/DialogCommit.vue b/src/components/DialogCommit.vue
index 71fc654..a3dd782 100644
--- a/src/components/DialogCommit.vue
+++ b/src/components/DialogCommit.vue
@@ -342,7 +342,6 @@ export default {
type: value.fileStatus
});
if (!this.errorRequest) {
- debugger;
createBlobs(value.value)
.then((res) => {
diff --git a/src/components/FileExplorer.vue b/src/components/FileExplorer.vue
index 48570f4..0e34f0c 100644
--- a/src/components/FileExplorer.vue
+++ b/src/components/FileExplorer.vue
@@ -303,7 +303,6 @@ export default {
createNewAdr({ repository }) {
let newAdr = store.createNewAdr(repository.repository);
// Open the new adr.
- debugger;
store.openAdrBy(repository.fullName, newAdr.path.split("/").pop());
}
}
diff --git a/src/plugins/api.js b/src/plugins/api.js
index 0267b29..0fe8260 100644
--- a/src/plugins/api.js
+++ b/src/plugins/api.js
@@ -8,6 +8,8 @@ let repoOwner = "";
let repoName = "";
let branch = "";
+axios.defaults.headers.common['Authorization'] = getHeaders().Authorization;
+
export function setInfosForApi(currRepoOwner, currRepoName, currBranch) {
repoName = currRepoName;
repoOwner = currRepoOwner;
@@ -21,9 +23,8 @@ export function setInfosForApi(currRepoOwner, currRepoName, currBranch) {
* @returns {Promise} the array of emails with attributes 'email', 'primary', 'verified', 'visibility'
*/
export async function getUserEmail() {
- const headers = getHeaders();
return axios
- .get(`${BASE_URL_USER}/public_emails`, { headers })
+ .get(`${BASE_URL_USER}/public_emails`)
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -37,8 +38,7 @@ export async function getUserEmail() {
* @returns {Promise} the array of informations with attributes 'login', 'name', etc.
*/
export async function getUserName() {
- const headers = getHeaders()
- return axios.get(BASE_URL_USER, { headers })
+ return axios.get(BASE_URL_USER)
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -53,7 +53,7 @@ export async function getUserName() {
*/
export async function getCommitSha() {
const headers = getHeaders()
- return axios.get(`${BASE_URL_REPO}/${repoOwner}/${repoName}/branches/${branch}`, { headers })
+ return axios.get(`${BASE_URL_REPO}/${repoOwner}/${repoName}/branches/${branch}`)
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -75,7 +75,7 @@ export async function createBlobs(file) {
({
content: file,
encoding: "utf-8"
- }), { headers: copyHeader })
+ }))
.then((response) => response.data)
.then((body) => body)
.catch((err) => {
@@ -92,12 +92,11 @@ export async function createBlobs(file) {
* @returns {Promise} informations about the newly created tree with attributes 'sha', etc.
*/
export async function createFileTree(lastCommitSha, folderTree) {
- const headers = getHeaders()
return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/trees`, {
base_tree: lastCommitSha,
tree: folderTree
- }, { headers })
+ })
.then((response) => response.data)
.then((body) => body)
.catch((err) => {
@@ -116,14 +115,13 @@ export async function createFileTree(lastCommitSha, folderTree) {
* @returns {Promise} informations about the created commit with attributes 'sha', etc.
*/
export async function createCommit(commitMessage, authorInfos, lastCommitSha, treeSha) {
- const headers = getHeaders()
return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/commits`, {
message: commitMessage,
author: authorInfos,
parents: [lastCommitSha],
tree: treeSha
- }, { headers })
+ })
.then((response) => response.data)
.then((body) => body)
.catch((err) => {
@@ -139,11 +137,10 @@ export async function createCommit(commitMessage, authorInfos, lastCommitSha, tr
* @returns {Promise} informations about the reference.
*/
export async function pushToGitHub(newCommitSha) {
- const headers = getHeaders()
return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/refs/heads/${branch}`, {
ref: "refs/heads/" + branch,
sha: newCommitSha
- }, { headers })
+ })
.then((response) => response.data)
.then((body) => body)
.catch((err) => {
@@ -164,7 +161,6 @@ export async function pushToGitHub(newCommitSha) {
*/
export async function loadRepositoryList(searchText = "", page = 1, perPage = 5) {
-
try {
const userId = localStorage.getItem('user');
@@ -186,9 +182,7 @@ export async function loadRepositoryList(searchText = "", page = 1, perPage = 5)
}`
};
- const response = await axios.post('https://api.github.com/graphql', body, {
- headers: getHeaders()
- });
+ const response = await axios.post('https://api.github.com/graphql', body);
if (!response?.data) {
return [];
@@ -260,9 +254,8 @@ export async function searchRepositoryList(searchString, maxResults = 2, searchR
*/
export async function loadFileTreeOfRepository(repoFullName, branch) {
- const headers = getHeaders()
- return axios.get(`${BASE_URL_REPO}/${repoFullName}/git/trees/${branch}?recursive=1`, { headers })
+ return axios.get(`${BASE_URL_REPO}/${repoFullName}/git/trees/${branch}?recursive=1`)
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -279,9 +272,8 @@ export async function loadFileTreeOfRepository(repoFullName, branch) {
* @returns {Promise<{ name : string }[]>} the fetched array of branches
*/
export async function loadBranchesName(repoName, username) {
- const headers = getHeaders()
return axios
- .get(`${BASE_URL_REPO}/${username}/${repoName}/branches?per_page=999`, { headers })
+ .get(`${BASE_URL_REPO}/${username}/${repoName}/branches?per_page=999`)
.then((response) => response.data)
.catch((err) => {
console.log(err);
@@ -299,7 +291,6 @@ export async function loadBranchesName(repoName, username) {
* @returns {Promise} a promise with the raw content of the specified file
*/
export async function loadRawFile(repoFullName, branch, filePath) {
- const headers = getHeaders()
if (typeof branch !== "string" || typeof branch != "string") {
console.log(
@@ -312,9 +303,7 @@ export async function loadRawFile(repoFullName, branch, filePath) {
);
} else {
return axios
- .get(`${BASE_URL_REPO}/${repoFullName}/contents/${filePath}?ref=${branch}`, {
- headers
- })
+ .get(`${BASE_URL_REPO}/${repoFullName}/contents/${filePath}?ref=${branch}`)
.then((response) => response.data)
.then((response) => decodeUnicode(response.content))
.catch((err) => {
From f6ba8f88ff13191adfee63ccd4ced6f16462257c Mon Sep 17 00:00:00 2001
From: Moneeza Syed <14besemsyed@seecs.edu.pk>
Date: Sat, 2 Dec 2023 20:32:50 +0100
Subject: [PATCH 11/19] fixed axios interceptor
---
src/components/ConnectToGitHubButton.vue | 5 +++--
src/plugins/api.js | 4 +---
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/components/ConnectToGitHubButton.vue b/src/components/ConnectToGitHubButton.vue
index 9e3d5e2..c4b6d11 100644
--- a/src/components/ConnectToGitHubButton.vue
+++ b/src/components/ConnectToGitHubButton.vue
@@ -7,8 +7,8 @@