## Description ### Fixes - [x] https://github.com/appsmithorg/appsmith/issues/19383 - [x] https://github.com/appsmithorg/appsmith/issues/19384 - [x] https://github.com/appsmithorg/appsmith/issues/19385 - [x] https://github.com/appsmithorg/appsmith/issues/19386 - [x] https://github.com/appsmithorg/appsmith/issues/19387 - [x] https://github.com/appsmithorg/appsmith/issues/19388 - [x] https://github.com/appsmithorg/appsmith/issues/19389 - [x] https://github.com/appsmithorg/appsmith/issues/19390 - [x] https://github.com/appsmithorg/appsmith/issues/19391 - [x] https://github.com/appsmithorg/appsmith/issues/19392 - [x] https://github.com/appsmithorg/appsmith/issues/19393 - [x] https://github.com/appsmithorg/appsmith/issues/19394 - [x] https://github.com/appsmithorg/appsmith/issues/19395 - [x] https://github.com/appsmithorg/appsmith/issues/19396 - [x] https://github.com/appsmithorg/appsmith/issues/19397 - [x] https://github.com/appsmithorg/appsmith/issues/19398 - [x] https://github.com/appsmithorg/appsmith/issues/19399 - [x] https://github.com/appsmithorg/appsmith/issues/19400 - [x] https://github.com/appsmithorg/appsmith/issues/19401 - [x] https://github.com/appsmithorg/appsmith/issues/19402 - [x] https://github.com/appsmithorg/appsmith/issues/19403 - [x] https://github.com/appsmithorg/appsmith/issues/19404 - [x] https://github.com/appsmithorg/appsmith/issues/19405 - [x] https://github.com/appsmithorg/appsmith/issues/19406 - [x] https://github.com/appsmithorg/appsmith/issues/19407 - [x] https://github.com/appsmithorg/appsmith/issues/19408 - [x] https://github.com/appsmithorg/appsmith/issues/19409 Fixes # (issue) > if no issue exists, please create an issue and ask the maintainers about this first Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update ## How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. > Please also list any relevant details for your test configuration. > Delete anything that is not important - Manual - Jest - Cypress ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Ankita Kinger <ankita@appsmith.com> Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvi@appsmith.com> Co-authored-by: Arsalan <arsalanyaldram0211@outlook.com> Co-authored-by: Aman Agarwal <aman@appsmith.com> Co-authored-by: Rohit Agarwal <rohit_agarwal@live.in> Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com> Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com> Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local> Co-authored-by: Vijetha-Kaja <vijetha@appsmith.com> Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io> Co-authored-by: Saroj <43822041+sarojsarab@users.noreply.github.com> Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Preet Sidhu <preetsidhu.bits@gmail.com> Co-authored-by: Vijetha-Kaja <119562824+Vijetha-Kaja@users.noreply.github.com> Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
254 lines
8.8 KiB
TypeScript
254 lines
8.8 KiB
TypeScript
import { ObjectsRegistry } from "../Objects/Registry";
|
|
const GITHUB_API_BASE = "https://api.github.com";
|
|
//const GITEA_API_BASE = "http://35.154.225.218";
|
|
|
|
import datasourceFormData from "../../fixtures/datasources.json";
|
|
|
|
export class GitSync {
|
|
public agHelper = ObjectsRegistry.AggregateHelper;
|
|
public locator = ObjectsRegistry.CommonLocators;
|
|
|
|
private _connectGitBottomBar = ".t--connect-git-bottom-bar";
|
|
private _gitSyncModal = ".git-sync-modal";
|
|
private _closeGitSyncModal =
|
|
"//div[@data-testid='t--git-sync-modal']//button[@aria-label='Close']";
|
|
//private _closeGitSyncModal = ".ads-v2-modal__content-header-close-button";
|
|
private _gitRepoInput =
|
|
"//label[text()='Remote URL']/following-sibling::div//input";
|
|
private _useDefaultConfig = "//label[text()='Use default configuration']";
|
|
private _gitConfigNameInput =
|
|
"//label[text()='Author name']/following-sibling::div//input";
|
|
private _gitConfigEmailInput =
|
|
"//label[text()='Author email']/following-sibling::div//input";
|
|
_branchButton = ".t--branch-button";
|
|
private _branchSearchInput = ".t--branch-search-input input";
|
|
private _bottomBarCommit = ".t--bottom-bar-commit button";
|
|
_bottomBarPull = ".t--bottom-bar-pull button";
|
|
private _branchName = (branch: string) =>
|
|
"//button[contains(@class, 't--branch-button')]//*[text()='" +
|
|
branch +
|
|
"']";
|
|
_checkMergeability = "//span[contains(text(), 'Checking mergeability')]";
|
|
|
|
OpenGitSyncModal() {
|
|
this.agHelper.GetNClick(this._connectGitBottomBar);
|
|
this.agHelper.AssertElementVisible(this._gitSyncModal);
|
|
}
|
|
|
|
CloseGitSyncModal() {
|
|
this.agHelper.GetNClick(this._closeGitSyncModal);
|
|
this.agHelper.AssertElementAbsence(this._gitSyncModal);
|
|
}
|
|
|
|
CreateNConnectToGit(
|
|
repoName = "Test",
|
|
assertConnect = true,
|
|
privateFlag = false,
|
|
) {
|
|
this.agHelper.GenerateUUID();
|
|
cy.get("@guid").then((uid) => {
|
|
repoName += uid;
|
|
this.CreateTestGiteaRepo(repoName, privateFlag);
|
|
//this.CreateLocalGithubRepo(repoName);
|
|
this.AuthorizeKeyToGitea(repoName, assertConnect);
|
|
// cy.get("@remoteUrl").then((remoteUrl: any) => {
|
|
// this.AuthorizeLocalGitSSH(remoteUrl);
|
|
// });
|
|
cy.wrap(repoName).as("gitRepoName");
|
|
});
|
|
}
|
|
|
|
public CreateTestGiteaRepo(repo: string, privateFlag = false) {
|
|
cy.request({
|
|
method: "POST",
|
|
url: `${datasourceFormData["GITEA_API_BASE_TED"]}:${datasourceFormData["GITEA_API_PORT_TED"]}/api/v1/org/Cypress/repos`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
|
|
},
|
|
body: {
|
|
name: repo,
|
|
private: privateFlag,
|
|
},
|
|
});
|
|
}
|
|
|
|
public AuthorizeKeyToGitea(repo: string, assertConnect = true) {
|
|
let generatedKey;
|
|
this.OpenGitSyncModal();
|
|
cy.intercept("POST", "/api/v1/applications/ssh-keypair/*").as(
|
|
`generateKey-${repo}`,
|
|
);
|
|
|
|
this.agHelper.AssertAttribute(
|
|
this._gitRepoInput,
|
|
"placeholder",
|
|
"git@example.com:user/repository.git",
|
|
);
|
|
this.agHelper.TypeText(
|
|
this._gitRepoInput,
|
|
`${datasourceFormData["GITEA_API_URL_TED"]}/${repo}.git`,
|
|
//`git@github.com:${owner}/${repo}.git`,
|
|
);
|
|
|
|
this.agHelper.ClickButton("Generate key");
|
|
|
|
cy.wait(`@generateKey-${repo}`).then((result: any) => {
|
|
generatedKey = result.response.body.data.publicKey;
|
|
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
|
|
// fetch the generated key and post to the github repo
|
|
cy.request({
|
|
method: "POST",
|
|
url: `${datasourceFormData["GITEA_API_BASE_TED"]}:${datasourceFormData["GITEA_API_PORT_TED"]}/api/v1/repos/Cypress/${repo}/keys`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
|
|
},
|
|
body: {
|
|
title: "key0",
|
|
key: generatedKey,
|
|
read_only: false,
|
|
},
|
|
});
|
|
|
|
this.agHelper.GetNClick(this._useDefaultConfig); //Uncheck the Use default configuration
|
|
this.agHelper.TypeText(
|
|
this._gitConfigNameInput,
|
|
"testusername",
|
|
//`{selectall}${testUsername}`,
|
|
);
|
|
this.agHelper.TypeText(this._gitConfigEmailInput, "test@test.com");
|
|
this.agHelper.ClickButton("Connect");
|
|
if (assertConnect) {
|
|
this.agHelper.ValidateNetworkStatus("@connectGitLocalRepo");
|
|
this.agHelper.AssertElementExist(this._bottomBarCommit, 0, 30000);
|
|
this.CloseGitSyncModal();
|
|
}
|
|
});
|
|
}
|
|
|
|
DeleteTestGithubRepo(repo: any) {
|
|
cy.request({
|
|
method: "DELETE",
|
|
url: `${datasourceFormData["GITEA_API_BASE_TED"]}:${datasourceFormData["GITEA_API_PORT_TED"]}/api/v1/repos/Cypress/${repo}`,
|
|
headers: {
|
|
Authorization: `token ${Cypress.env("GITEA_TOKEN")}`,
|
|
},
|
|
});
|
|
}
|
|
|
|
CreateGitBranch(branch = "Test", toUseNewGuid = false) {
|
|
if (toUseNewGuid) this.agHelper.GenerateUUID();
|
|
this.agHelper.AssertElementExist(this._bottomBarCommit);
|
|
this.agHelper.GetNClick(this._branchButton);
|
|
this.agHelper.Sleep(2000); //branch pop up to open
|
|
cy.get("@guid").then((uid) => {
|
|
//using the same uid as generated during CreateNConnectToGit
|
|
this.agHelper.TypeText(
|
|
this._branchSearchInput,
|
|
`{selectall}` + `${branch + uid}` + `{enter}`,
|
|
0,
|
|
true,
|
|
);
|
|
this.agHelper.AssertElementExist(this.locator._runBtnSpinner);
|
|
this.agHelper.AssertElementAbsence(this.locator._runBtnSpinner, 70000); //Since page taking more time to laod in some cases
|
|
this.agHelper.AssertElementVisible(this._branchName(branch + uid));
|
|
cy.wrap(branch + uid).as("gitbranchName");
|
|
});
|
|
}
|
|
|
|
//#region Unused methods
|
|
|
|
private AuthorizeLocalGitSSH(remoteUrl: string, assertConnect = true) {
|
|
let generatedKey;
|
|
this.OpenGitSyncModal();
|
|
this.agHelper.AssertAttribute(
|
|
this._gitRepoInput,
|
|
"placeholder",
|
|
"git@example.com:user/repository.git",
|
|
);
|
|
this.agHelper.TypeText(this._gitRepoInput, remoteUrl);
|
|
|
|
this.agHelper.ClickButton("Generate key");
|
|
|
|
cy.wait(`@generateKey`).then((result: any) => {
|
|
generatedKey = result.response.body.data.publicKey;
|
|
generatedKey = generatedKey.slice(0, generatedKey.length - 1);
|
|
let formdata = new FormData();
|
|
cy.log("generatedKey is " + generatedKey);
|
|
formdata.set("sshkey", generatedKey);
|
|
// fetch the generated key and post to the github repo
|
|
cy.request({
|
|
method: "POST",
|
|
url: `http://${datasourceFormData["GITEA_API_BASE_TED"]}:${datasourceFormData["GITEA_API_PORT_TED"]}/v1/gitserver/addgitssh`,
|
|
//body: formdata,
|
|
body: {
|
|
sshkey: generatedKey,
|
|
},
|
|
form: true,
|
|
// headers: {
|
|
// "Content-Type": "application/x-www-form-urlencoded"
|
|
// },
|
|
}).then((response) => {
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
this.agHelper.GetNClick(this._useDefaultConfig); //Uncheck the Use default configuration
|
|
this.agHelper.TypeText(
|
|
this._gitConfigNameInput,
|
|
"testusername",
|
|
//`{selectall}${testUsername}`,
|
|
);
|
|
this.agHelper.TypeText(this._gitConfigEmailInput, "test@test.com");
|
|
this.agHelper.ClickButton("CONNECT");
|
|
|
|
if (assertConnect) {
|
|
//this.ReplaceForGit("cypress/fixtures/Bugs/GitConnectResponse.json", remoteUrl);
|
|
//cy.get('@connectGitLocalRepo').its('response.statusCode').should('equal', 200);
|
|
// cy.intercept("POST", "/api/v1/git/connect/app/*", {
|
|
// fixture: "/Bugs/GitConnectResponse.json",
|
|
// });
|
|
this.agHelper.ValidateNetworkStatus("@connectGitLocalRepo");
|
|
}
|
|
this.CloseGitSyncModal();
|
|
});
|
|
}
|
|
|
|
private ReplaceForGit(fixtureFile: any, remoteUrl: string) {
|
|
let currentAppId, currentURL;
|
|
cy.readFile(
|
|
fixtureFile,
|
|
// (err: string) => {
|
|
// if (err) {
|
|
// return console.error(err);
|
|
// }}
|
|
).then((data) => {
|
|
cy.url().then((url) => {
|
|
currentURL = url;
|
|
const myRegexp = /page-1(.*)/;
|
|
const match = myRegexp.exec(currentURL);
|
|
cy.log(currentURL + "currentURL from intercept is");
|
|
currentAppId = match ? match[1].split("/")[1] : null;
|
|
data.data.id = currentAppId;
|
|
data.data.gitApplicationMetadata.defaultApplicationId = currentAppId;
|
|
data.data.gitApplicationMetadata.remoteUrl = remoteUrl;
|
|
cy.writeFile(fixtureFile, JSON.stringify(data));
|
|
});
|
|
});
|
|
}
|
|
|
|
private CreateLocalGithubRepo(repo: string) {
|
|
let remoteUrl = "";
|
|
cy.request({
|
|
method: "GET",
|
|
url:
|
|
`http://${datasourceFormData["GITEA_API_BASE_TED"]}:${datasourceFormData["GITEA_API_PORT_TED"]}/v1/gitserver/addrepo?reponame=` +
|
|
repo,
|
|
}).then((response) => {
|
|
remoteUrl = JSON.stringify(response.body).replace(/['"]+/g, "");
|
|
expect(response.status).to.equal(200);
|
|
//cy.log("remoteUrl is"+ remoteUrl);
|
|
cy.wrap(remoteUrl).as("remoteUrl");
|
|
});
|
|
}
|
|
|
|
//#endregion
|
|
}
|