Created
November 9, 2023 19:27
-
-
Save apla/9eec4adfb9b1b8aa14c878c4cd8588f9 to your computer and use it in GitHub Desktop.
GitHub releases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const accessToken = 'YOUR_GITHUB_ACCESS_TOKEN'; | |
const repoOwner = 'REPO_OWNER'; | |
const repoName = 'REPO_NAME'; | |
const productionTag = 'production/<number>'; | |
const targetBranch = 'development'; | |
async function findRecentReleaseCommit(branch) { | |
const accessToken = 'YOUR_GITHUB_ACCESS_TOKEN'; // Replace with your GitHub access token | |
const url = `https://api.github.com/repos/${repoOwner}/${repoName}/commits?sha=${branch}`; | |
try { | |
const response = await fetch(url, { | |
method: 'GET', | |
headers: { | |
Authorization: `Bearer ${accessToken}`, | |
'User-Agent': 'GitHub Commit Search', | |
}, | |
}); | |
if (response.status !== 200) { | |
throw new Error(`GitHub API request failed with status code ${response.status}`); | |
} | |
const commits = await response.json(); | |
for (const commit of commits) { | |
if (commit.commit.message.startsWith('release')) { | |
return commit; | |
} | |
} | |
return null; // No matching commit found | |
} catch (error) { | |
console.error('Error:', error.message); | |
return null; | |
} | |
} | |
async function getCommitsBetweenTags() { | |
try { | |
// Get the SHA of the production tag | |
const tagInfoResponse = await fetch( | |
`https://api.github.com/repos/${repoOwner}/${repoName}/git/refs/tags/${productionTag}` | |
); | |
const tagInfo = await tagInfoResponse.json(); | |
const productionTagSHA = tagInfo.object.sha; | |
// Get the latest commit on the current branch | |
const branchInfoResponse = await fetch( | |
`https://api.github.com/repos/${repoOwner}/${repoName}/branches/${targetBranch}` | |
); | |
const branchInfo = await branchInfoResponse.json(); | |
const currentBranchSHA = branchInfo.commit.sha; | |
// Get the list of commits between the production tag and the current branch | |
const commitListResponse = await fetch( | |
`https://api.github.com/repos/${repoOwner}/${repoName}/compare/${productionTagSHA}...${currentBranchSHA}` | |
); | |
const commitList = await commitListResponse.json(); | |
const commitSHAs = commitList.commits.map(commit => commit.sha); | |
for (const commitSHA of commitSHAs) { | |
// Get the associated pull request for each commit | |
const prInfoResponse = await fetch( | |
`https://api.github.com/repos/${repoOwner}/${repoName}/commits/${commitSHA}/pulls` | |
); | |
const prInfo = await prInfoResponse.json(); | |
if (prInfo.length > 0) { | |
console.log(`PR Title: ${prInfo[0].title}`); | |
console.log(`Commit SHA: ${commitSHA}`); | |
console.log('-----------------------'); | |
} | |
} | |
} catch (error) { | |
console.error('Error:', error.message); | |
} | |
} | |
getCommitsBetweenTags(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment