Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: include PR title in test name #12

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export class Util {
return {valid, validation};
}

public static convertPrepareObjectToTestIOPayload(prepareObject: any, repo: string, owner: string, pr: number): any {
public static convertPrepareObjectToTestIOPayload(prepareObject: any, repo: string, owner: string, pr: number, prTitle: string): any {
const titleBase = `[${owner}/${repo}/${pr}]${prTitle}`;
const testioPayload = {
exploratory_test: {
test_title: `${owner}/${repo}/${pr}`,
test_title: titleBase,
test_environment: {
title: `${owner}/${repo}/${pr} test environment`,
title: `${titleBase} [test environment]`,
url: prepareObject.test_environment.url,
access: prepareObject.test_environment.access,
},
Expand Down
18 changes: 17 additions & 1 deletion src/retrievePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,23 @@ async function createPayload() {
Util.throwErrorAndPrepareErrorMessage("Provided json is not conform to schema", errorFileName);
}

const testIOPayload = Util.convertPrepareObjectToTestIOPayload(preparation, github.context.repo.repo, github.context.repo.owner, github.context.issue.number);
const pullRequest:any = await octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: github.context.issue.number,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})

const prTitle = pullRequest.title;
if (!prTitle) {
console.log("The pull request received:");
console.log(JSON.stringify(pullRequest, null, 2));
Util.throwErrorAndPrepareErrorMessage("Could not retrieve title of the PR", errorFileName);
}

const testIOPayload = Util.convertPrepareObjectToTestIOPayload(preparation, github.context.repo.repo, github.context.repo.owner, github.context.issue.number, prTitle);
console.log("Converted payload:");
console.log(testIOPayload);
const payloadFile = `${process.env.TESTIO_SCRIPTS_DIR}/resources/testio_payload.json`;
Expand Down
7 changes: 4 additions & 3 deletions test/Util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ describe("TestIO Trigger-from-PR logic", () => {
const owner = "Staffbase";
const pr = 666;
const commentID = 123456;
const testioPayload = Util.convertPrepareObjectToTestIOPayload(prepareObject, repo, owner, pr);
const testName = `${owner}/${repo}/${pr}`;
const prTitle = "My awesome feature";
const testioPayload = Util.convertPrepareObjectToTestIOPayload(prepareObject, repo, owner, pr, prTitle);
const testName = `[${owner}/${repo}/${pr}]${prTitle}`;
expect(testioPayload.exploratory_test.test_title).toBe(testName);
expect(testioPayload.exploratory_test.test_environment.title).toBe(testName + " test environment");
expect(testioPayload.exploratory_test.test_environment.title).toBe(testName + " [test environment]");
expect(testioPayload.exploratory_test.test_environment.url).toBe(prepareObject.test_environment.url);
expect(testioPayload.exploratory_test.test_environment.access).toBe(prepareObject.test_environment.access);
expect(testioPayload.exploratory_test.features[0].title).toBe(prepareObject.feature.title);
Expand Down