diff --git a/src/Util.ts b/src/Util.ts index bb4787f..ded69c2 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -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, }, diff --git a/src/retrievePayload.ts b/src/retrievePayload.ts index e827d8b..ea48807 100644 --- a/src/retrievePayload.ts +++ b/src/retrievePayload.ts @@ -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`; diff --git a/test/Util.test.ts b/test/Util.test.ts index 7490b24..723e901 100644 --- a/test/Util.test.ts +++ b/test/Util.test.ts @@ -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);