Skip to content

Commit

Permalink
added gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
Moneexa committed Jan 5, 2024
1 parent 5f191bc commit 9db9fd3
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 53 deletions.
15 changes: 9 additions & 6 deletions cypress/e2e/adrManagerTest/ChooseSourceControl.cy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { TEST_BASE_URL } from "../../support/e2e";
context("Choosing from different source control soptions", () => {
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);
})

it('Different source control options should be visible', () => {
cy.visit("http://localhost:8000/adr-manager/#/");
cy.get("[data-cy=disconnect]").click();
cy.get("[data-cy=disconnect]").click()
cy.get("[data-cy=connectToGithub]").click();
cy.get("[data-cy=loadOptions]").should('exist');
});
it('Clicking should open oauth window', () => {
cy.get("[data-cy=signInWithGithubFree]").click()

})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"serve": "vite preview",
"test": "jest",
"e2e:test": "cypress run",
"e2e:test-ci": "cypress run --browser chrome --headed --config video=false,screenshotOnRunFailure=false",
"e2e:test-ci": "cypress run --browser chrome --headed --config video=false,screenshotOnRunFailure=false --spec cypress/e2e/adrManagerTest/ChooseSourceControl.cy.js",
"format": "prettier --write . --ignore-unknown"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConnectToGitHubButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</template>

<script>
import DialogShowOptions from "./sourceControlOptions/DialogShowOptions.vue"
import DialogShowOptions from "./DialogShowOptions.vue"
export default {
name: "connectGitHub",
components: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DialogAddRepositories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</template>

<script>
import { loadRepositoryList, searchRepositoryList, loadAllRepositoryContent } from "/src/plugins/api.js";
import { loadRepositoryList, searchRepositoryList, loadAllRepositoryContent } from "/src/plugins/githubApis/api";
import { store } from "/src/plugins/store.js";
import _ from "lodash";
Expand Down
2 changes: 1 addition & 1 deletion src/components/DialogCommit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
</template>

<script>
import { getCommitSha, createBlobs, createFileTree, createCommit, pushToGitHub } from "/src/plugins/api.js";
import { getCommitSha, createBlobs, createFileTree, createCommit, pushToGitHub } from "/src/plugins/githubApis/api.js";
import { store } from "../plugins/store";
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
</v-btn>
</div>
<div class="d-flex flex-column justify-content-center align-items-center m-5">
<SignInWithGithubFree />
<SignInWithGithubEnterprise />
<SignInWithGithub />
<SignInWithGitlab />
</div>
</v-card>
</v-dialog>
</template>
<script>
import SignInWithGithubFree from './github/SignInWithGithubFree.vue';
import SignInWithGithubEnterprise from './github/SignInWithGithubEnterprise.vue';
import SignInWithGithub from './sourceControlOptions/github/SignInWithGithubFree.vue';
import SignInWithGitlab from './sourceControlOptions/gitlab/SignInWithGitlab.vue';
export default {
data() {
return {
Expand All @@ -36,6 +36,6 @@ export default {
this.$emit('close-dialog');
},
},
components: { SignInWithGithubFree, SignInWithGithubEnterprise }
components: { SignInWithGithub, SignInWithGitlab }
};
</script>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-btn @click="signIn" color="primary" class="my-2" data-cy="signInWithgithubFree">
<v-btn @click="signIn" color="primary" class="my-2" data-cy="signInWithGithubFree">
<v-icon left>mdi-github</v-icon>
Sign In with GitHub Free Version
Sign In with GitHub
</v-btn>
</template>

Expand Down
14 changes: 4 additions & 10 deletions src/components/sourceControlOptions/github/signInWithGithub.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
// signInWithGithub.js
import { signInWithPopup, GithubAuthProvider } from "firebase/auth";
import { auth } from "../../../plugins/firebase/client";

export function signInWithGithub(githubEnterpriseInstance) {
debugger;
export function signInWithGithub() {
const githubProvider = new GithubAuthProvider()
githubProvider.addScope("repo read:user gist workflow read:org");
if (githubEnterpriseInstance) {
githubProvider.setCustomParameters({
login: githubInstanceUrl,
});
}

return signInWithPopup(auth, githubProvider)
.then((result) => {
const credential = GithubAuthProvider.credentialFromResult(result);
Expand All @@ -19,8 +13,8 @@ export function signInWithGithub(githubEnterpriseInstance) {
return { token, user };
})
.catch((error) => {
// Handle the error as needed
console.error("SignIn Error", error);
throw error; // rethrow the error to handle it in the component if needed
throw error;
});

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<template>
<v-btn @click="signIn" color="primary" class="my-2">
<v-icon left>mdi-github</v-icon>
Sign In with GitHub Enterprise Version
<v-icon left>mdi-gitlab</v-icon>
Sign In with Gitlab
</v-btn>
</template>

<script>
import { signInWithGithub } from './signInWithGithub';
import { signInWithGitlab } from './signInWithGitlab';
export default {
name: "SignInWithGithubEnterprise",
name: "SignInWithGitlab",
methods: {
signIn() {
console.log('came here')
signInWithGithub("https://your-github-enterprise-instance.com")
signInWithGitlab()
.then(({ token, user }) => {
localStorage.setItem("authId", token);
localStorage.setItem("user", user?.reloadUserInfo?.screenName);
localStorage.setItem("user", user?.reloadUserInfo?.localId);
this.$router.push({
name: "Editor",
params: { id: user }
Expand All @@ -25,8 +25,6 @@ export default {
console.error("Sign In Error", error);
});
}
}
}
</script>
</script>
21 changes: 21 additions & 0 deletions src/components/sourceControlOptions/gitlab/signInWithGitlab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth";

export function signInWithGitlab() {

const auth = getAuth();
const provider = new OAuthProvider('oidc.test-adr');
provider.addScope("read_user");
return signInWithPopup(auth, provider)
.then((result) => {
const credential = OAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
debugger;
const user = result.user;
return { token, user };
})
.catch((error) => {
console.error("SignIn Error", error);
throw error;
});

}
13 changes: 6 additions & 7 deletions src/plugins/firebase/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { initializeApp } from "firebase/app";
import { getAuth, GithubAuthProvider } from "firebase/auth";

const firebaseConfig = {
apiKey: "AIzaSyDLeDiHmseMx-w9Ba7TI4lL8Lvc0M7Zpeg",
authDomain: "adr-manager.firebaseapp.com",
projectId: "adr-manager",
storageBucket: "adr-manager.appspot.com",
messagingSenderId: "313525337788",
appId: "1:313525337788:web:0834a7a168fe39352adab9"
apiKey: "AIzaSyCzIScILC86RUQtYh6d3kjzpHphVhaQpGg",
authDomain: "moneeza-adr.firebaseapp.com",
projectId: "moneeza-adr",
storageBucket: "moneeza-adr.appspot.com",
messagingSenderId: "788415806002",
appId: "1:788415806002:web:00adb948f863c057e8da2b"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/api.js → src/plugins/githubApis/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This file contains any calls to the backend. */

import { Repository } from "./classes.js";
import { Repository } from "../classes.js";
import axios from "axios";
import { BASE_URL_REPO, BASE_URL_USER } from "./apiConfig/config.js";
import { BASE_URL_REPO, BASE_URL_USER } from "../apiConfig/config.js";

let repoOwner = "";
let repoName = "";
Expand Down Expand Up @@ -260,11 +260,11 @@ export async function loadRawFile(repoFullName, branch, filePath) {
if (typeof branch !== "string" || typeof branch != "string") {
console.log(
"Invalid values for loadContentsForRepository. Given Repository full name: " +
repoFullName +
", Branch:" +
branch +
", file path: " +
filePath
repoFullName +
", Branch:" +
branch +
", file path: " +
filePath
);
} else {
return axios
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import _ from "lodash";
import sanitize from "sanitize-filename";
import { ArchitecturalDecisionRecord, Repository } from "./classes";
import { adr2md, naturalCase2snakeCase } from "./parser";
import { setInfosForApi, getUserName, getUserEmail } from "./api";
import { setInfosForApi, getUserName, getUserEmail } from "./githubApis/api";

export const store = new Vue({
data: {
Expand Down
2 changes: 1 addition & 1 deletion src/views/EditorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</template>

<script>
import { loadBranchesName, loadARepositoryContent } from "/src/plugins/api.js";
import { loadBranchesName, loadARepositoryContent } from "/src/plugins/githubApis/api";
import { store } from "/src/plugins/store.js";
import { Splitpanes, Pane } from "splitpanes";
Expand Down

0 comments on commit 9db9fd3

Please sign in to comment.