Can anyone tell me that how to fetch the user name who merged the pr by the octokit.request api call.
I can fetch all the prs from octokit.request method with the query parameter state=all value. It is returning the array having all PRs (open and closed all). We can see that PRs with merged_at value is not equal to null are the pr which are merged.
Now how to find the user name who merged this pr.
Let me answer my question.
These are the steps.
commit.commit.commiter.name==='GitHub
'. this will filter and take those commit only by which the PR is merged.mergedPRs.user.login === filteredCommit.commit.author.login
. const allCommits : Array<any> = await getAllCommits(data);
const mergedPRs : Array<any> = await getMergedPRs(data);
const MergeCommitsUserDetailsWithsha : Array<UserWithCommitSha> = []
allCommits.forEach(commit => {
if(commit.commit.committer.name==="GitHub"){
let objectToPush : UserWithCommitSha = {username:commit.author.login, commitsha:commit.sha};
MergeCommitsUserDetailsWithsha.push(objectToPush);
}
});
const selfMergedPRs : Array<any> = mergedPRs.filter(pr=>{
return MergeCommitsUserDetailsWithsha.some(element => element.username===pr.user.login && element.commitsha===pr.merge_commit_sha);
});
let result : Array<SelfMergedPRs>=[];
selfMergedPRs.forEach(pr => {
result.push({url:pr.html_url, userName:pr.user.login, commit:pr.merge_commit_sha, headBranch:pr.head.ref, baseBranch:pr.base.ref})
});
return result;