async function create_checks_by_pullRequest()

in azure-pipelines-wrapper/check_run.js [137:169]


async function  create_checks_by_pullRequest(context, owner, repo, pullRequestId){
    var payload = context.payload;
    var pullRequest = await context.octokit.pulls.get({
        owner: owner,
        repo: repo,
        pull_number: pullRequestId,
    });
    if (pullRequest.status != 200){
        console.error(`Failed to get pull request for ${owner}/${repo}/${pullRequestId}`);
        return null;
    }

    context.log(`Succeeded to get pull request for ${owner}/${repo}/${pullRequestId}`);
    var check_runs = await context.octokit.checks.listForRef({
        owner: owner,
        repo: repo,
        ref: pullRequest.data.head.sha,
        app_id: process.env.AZP_APP_ID,
    });

    if (check_runs.status != 200){
        console.error(`Failed to list checks for ${owner}/${repo}/${payload.check_run.head_sha} for app ${process.env.AZP_APP_ID}`);
        return null;
    }
    if (check_runs.data.check_runs.length <= 0){
        console.log(`No checks found for ${owner}/${repo}/${payload.check_run.head_sha} for app ${process.env.AZP_APP_ID}`);
        return null;
    }

    console.log(`Succeeded to list checks for ${owner}/${repo}/${pullRequest.data.head.sha}, checks count: ${check_runs.data.check_runs.length}`);
    var azp_check_run = check_runs.data.check_runs[0];
    await create_checks_by_azp_check_run(context, azp_check_run);    
}