Add targetBranch output indicating what is the target branch

Depending on type of the "source" event target branch output
indicates either the direct target branch (for pushes)
or targetBranch for the PR (for Pull Request)
diff --git a/README.md b/README.md
index 4947cd6..8e130dc 100644
--- a/README.md
+++ b/README.md
@@ -50,16 +50,17 @@
 
 ## Outputs
 
-| Output              | No `sourceRunId` specified                                                        | The `sourceRunId` set to `${{ github.event.workflow_run.id }}`                                       |
-|---------------------|-----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|
-| `sourceHeadRepo`    | Current repository. Format: `owner/repo`                                          | Repository of the run that triggered this `workflow_run`. Format: `owner/repo`                       |
-| `sourceHeadBranch`  | Current branch.                                                                   | Branch of the run that triggered this `workflow_run`. Might be forked repo, if it is a pull_request. |
-| `sourceHeadSha`     | Current commit SHA: `{{ github.sha }}`                                            | Commit sha of the run that triggered this `workflow_run`.                                            |
-| `mergeCommitSha`    | Merge commit SHA if PR-triggered event.                                           | Merge commit SHA if PR-triggered event.                                                              |
-| `targetCommitSha`   | Target commit SHA (merge if present, otherwise source).                           | Target commit SHA (merge if present, otherwise source).                                              |
-| `pullRequestNumber` | Number of the associated Pull Request (if PR triggered)                           | Number of the associated Pull Request (if PR triggered)                                              |
-| `pullRequestLabels` | Stringified JSON array of Labels of the associated Pull Request (if PR triggered) |  Stringified JSON array of Labels of the associated Pull Request (if PR triggered)                   |
-| `sourceEvent`       | Current event: ``${{ github.event }}``                                            | Event of the run that triggered this `workflow_run`                                                  |
+| Output               | No `sourceRunId` specified                                                          | The `sourceRunId` set to `${{ github.event.workflow_run.id }}`                                        |
+|----------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
+| `sourceHeadRepo`     | Current repository. Format: `owner/repo`                                            | Repository of the run that triggered this `workflow_run`. Format: `owner/repo`                        |
+| `sourceHeadBranch`   | Current branch.                                                                     | Branch of the run that triggered this `workflow_run`. Might be forked repo, if it is a pull_request.  |
+| `sourceHeadSha`      | Current commit SHA: `{{ github.sha }}`                                              | Commit sha of the run that triggered this `workflow_run`.                                             |
+| `mergeCommitSha`     | Merge commit SHA if PR-triggered event.                                             | Merge commit SHA if PR-triggered event.                                                               |
+| `targetCommitSha`    | Target commit SHA (merge if present, otherwise source).                             | Target commit SHA (merge if present, otherwise source).                                               |
+| `pullRequestNumber`  | Number of the associated Pull Request (if PR triggered)                             | Number of the associated Pull Request (if PR triggered)                                               |
+| `pullRequestLabels`  | Stringified JSON array of Labels of the associated Pull Request (if PR triggered)   | Stringified JSON array of Labels of the associated Pull Request (if PR triggered)                     |
+| `targetBranch`       | Target branch of the pull request or target branch for push                         | Target branch of the pull request or target branch for push                                           |
+| `sourceEvent`        | Current event: ``${{ github.event }}``                                              | Event of the run that triggered this `workflow_run`                                                   |
 
 # Examples
 
@@ -83,6 +84,7 @@
       targetCommitSha: ${{ steps.workflow-run-info.outputs.targetCommitSha }}
       pullRequestNumber: ${{ steps.workflow-run-info.outputs.pullRequestNumber }}
       pullRequestLabels: ${{ steps.workflow-run-info.outputs.pullRequestLabels }}
+      targetBranch: ${{ steps.source-run-info.outputs.targetBranch }}
       sourceEvent: ${{ steps.workflow-run-info.outputs.sourceEvent }}
     steps:
       - name: "Get information about the current run"
@@ -114,8 +116,8 @@
       targetCommitSha: ${{ steps.source-run-info.outputs.targetCommitSha }}
       pullRequestNumber: ${{ steps.source-run-info.outputs.pullRequestNumber }}
       pullRequestLabels: ${{ steps.source-run-info.outputs.pullRequestLabels }}
+      targetBranch: ${{ steps.source-run-info.outputs.targetBranch }}
       sourceEvent: ${{ steps.source-run-info.outputs.sourceEvent }}
-
     steps:
       - name: "Get information about the origin 'CI' run"
         uses: potiuk/get-workflow-origin@v1_1
diff --git a/dist/index.js b/dist/index.js
index 51248f6..59979da 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1493,7 +1493,8 @@
         for (const pullRequest of pullRequests) {
             core.info(`\nComparing: ${pullRequest.number} sha: ${pullRequest.head.sha} with expected: ${headSha}.\n`);
             if (pullRequest.head.sha === headSha) {
-                core.info(`\nFound PR: ${pullRequest.number}\n`);
+                core.info(`\nFound PR: ${pullRequest.number}. ` +
+                    `Url: https://api.github.com/repos/${owner}/${repo}/pulls/${pullRequest.number}\n`);
                 return pullRequest;
             }
         }
@@ -1510,6 +1511,7 @@
             run_id: runId
         });
         const sourceRun = reply.data;
+        core.debug(JSON.stringify(reply.data));
         core.info(`Source workflow: Head repo: ${sourceRun.head_repository.full_name}, ` +
             `Head branch: ${sourceRun.head_branch} ` +
             `Event: ${sourceRun.event}, Head sha: ${sourceRun.head_sha}, url: ${sourceRun.url}`);
@@ -1524,6 +1526,7 @@
             reply.data.event,
             reply.data.head_sha,
             pullRequest ? pullRequest.merge_commit_sha : '',
+            pullRequest ? pullRequest.base.ref : reply.data.head_branch,
             pullRequest
         ];
     });
@@ -1541,13 +1544,13 @@
         const eventName = getRequiredEnv('GITHUB_EVENT_NAME');
         const sourceRunId = parseInt(core.getInput('sourceRunId')) || selfRunId;
         const [owner, repo] = repository.split('/');
-        // core.info(`\nPayload: ${JSON.stringify(github.context.payload)}\n`)
+        core.debug(`\nPayload: ${JSON.stringify(github.context.payload)}\n`);
         core.info(`\nGetting workflow id for source run id: ${sourceRunId}, owner: ${owner}, repo: ${repo}\n`);
         const sourceWorkflowId = yield getWorkflowId(octokit, sourceRunId, owner, repo);
         core.info(`Repository: ${repository}, Owner: ${owner}, Repo: ${repo}, ` +
             `Event name: ${eventName},` +
             `sourceWorkflowId: ${sourceWorkflowId}, sourceRunId: ${sourceRunId}, selfRunId: ${selfRunId}, `);
-        const [headRepo, headBranch, sourceEventName, headSha, mergeCommitSha, pullRequest] = yield getOrigin(octokit, sourceRunId, owner, repo);
+        const [headRepo, headBranch, sourceEventName, headSha, mergeCommitSha, targetBranch, pullRequest] = yield getOrigin(octokit, sourceRunId, owner, repo);
         verboseOutput('sourceHeadRepo', headRepo);
         verboseOutput('sourceHeadBranch', headBranch);
         verboseOutput('sourceHeadSha', headSha);
@@ -1557,6 +1560,7 @@
         verboseOutput('pullRequestLabels', JSON.stringify(labelNames));
         verboseOutput('mergeCommitSha', mergeCommitSha);
         verboseOutput('targetCommitSha', pullRequest ? mergeCommitSha : headSha);
+        verboseOutput('targetBranch', targetBranch);
     });
 }
 run()
diff --git a/src/main.ts b/src/main.ts
index 46b06ed..96d016a 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -52,7 +52,10 @@
       `\nComparing: ${pullRequest.number} sha: ${pullRequest.head.sha} with expected: ${headSha}.\n`
     )
     if (pullRequest.head.sha === headSha) {
-      core.info(`\nFound PR: ${pullRequest.number}\n`)
+      core.info(
+        `\nFound PR: ${pullRequest.number}. ` +
+          `Url: https://api.github.com/repos/${owner}/${repo}/pulls/${pullRequest.number}\n`
+      )
       return pullRequest
     }
   }
@@ -66,7 +69,15 @@
   owner: string,
   repo: string
 ): Promise<
-  [string, string, string, string, string, rest.PullsListResponseItem | null]
+  [
+    string,
+    string,
+    string,
+    string,
+    string,
+    string,
+    rest.PullsListResponseItem | null
+  ]
 > {
   const reply = await octokit.actions.getWorkflowRun({
     owner,
@@ -75,6 +86,7 @@
     run_id: runId
   })
   const sourceRun = reply.data
+  core.debug(JSON.stringify(reply.data))
   core.info(
     `Source workflow: Head repo: ${sourceRun.head_repository.full_name}, ` +
       `Head branch: ${sourceRun.head_branch} ` +
@@ -101,6 +113,7 @@
     reply.data.event,
     reply.data.head_sha,
     pullRequest ? pullRequest.merge_commit_sha : '',
+    pullRequest ? pullRequest.base.ref : reply.data.head_branch,
     pullRequest
   ]
 }
@@ -119,7 +132,7 @@
   const sourceRunId = parseInt(core.getInput('sourceRunId')) || selfRunId
   const [owner, repo] = repository.split('/')
 
-  // core.info(`\nPayload: ${JSON.stringify(github.context.payload)}\n`)
+  core.debug(`\nPayload: ${JSON.stringify(github.context.payload)}\n`)
 
   core.info(
     `\nGetting workflow id for source run id: ${sourceRunId}, owner: ${owner}, repo: ${repo}\n`
@@ -142,6 +155,7 @@
     sourceEventName,
     headSha,
     mergeCommitSha,
+    targetBranch,
     pullRequest
   ] = await getOrigin(octokit, sourceRunId, owner, repo)
 
@@ -157,6 +171,7 @@
   verboseOutput('pullRequestLabels', JSON.stringify(labelNames))
   verboseOutput('mergeCommitSha', mergeCommitSha)
   verboseOutput('targetCommitSha', pullRequest ? mergeCommitSha : headSha)
+  verboseOutput('targetBranch', targetBranch)
 }
 
 run()