-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script for searching for Cody commits by JetBrains version (#2356)
By running `pnpm run canhaz nnnn` where nnnn is a sourcegraph/cody commit, this script will print which JetBrains versions contain that commit. You must set the CODY_DIR environment variable to a sourcegraph/cody repo; this script will fetch commits in that repo. This reads version tags from the repo containing the working directory. If you need to fetch version tags, run the command mentioned in the script first. ## Test plan This adds a script, it does not affect the product. ``` $ CODY_DIR=~/dev/cody pnpm run canhaz 343d9cfe7539806f447f23e0f9a4be70dcf713c3 > @ canhaz C:\Users\DominicCooney\dev\jetbrains\scripts > ts-node canhaz.ts "343d9cfe7539806f447f23e0f9a4be70dcf713c3" This script checks whether a given JetBrains release contains a specific Cody commit. To fetch version git tags from origin, run: git fetch origin 'refs/tags/v*:refs/tags/v*' Using sourcegraph/cody repo in C:/Users/DominicCooney/dev/cody ✔️ v7.0.6-nightly ✔️ v7.0.6 ✔️ v7.0.5-nightly ✔️ v7.0.4-nightly ✔️ v7.0.4 ✔️ v7.0.3-nightly ✔️ v7.0.2-nightly ✔️ v7.0.2 ✔️ v7.0.1-nightly ✔️ v7.0.1 ✔️ v7.0.0-nightly ✔️ v7.0.0 ✔️ v6.0.38-nightly ✔️ v6.0.37-nightly ✔️ v6.0.36-nightly ✔️ v6.0.35-nightly ❌ v6.0.34-nightly ❌ v6.0.34 ❌ v6.0.33-nightly ✔️ v6.0.32-nightly ✔️ v6.0.31-nightly ❌ v6.0.30-nightly ❌ v6.0.29-nightly ❌ v6.0.28-nightly ❌ v6.0.27-experimental ```
- Loading branch information
1 parent
0d3ff42
commit 13ffe70
Showing
5 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* Checks whether a given JetBrains release contains a specific Cody commit. | ||
*/ | ||
|
||
const {execSync} = require("child_process"); | ||
|
||
console.log(` | ||
This script checks whether a given JetBrains release contains a specific Cody commit. | ||
To fetch version git tags from origin, run: | ||
git fetch origin 'refs/tags/v*:refs/tags/v*' | ||
`); | ||
|
||
// Check if CODY_DIR is set | ||
const CODY_DIR = process.env.CODY_DIR; | ||
if (CODY_DIR) { | ||
console.log(`Using sourcegraph/cody repo in ${CODY_DIR}`) | ||
} else { | ||
console.error('Error: CODY_DIR environment variable is not set.'); | ||
process.exit(1); | ||
} | ||
|
||
// Check if targetCommit is provided as a command-line argument | ||
const targetCommit = process.argv[2]; | ||
if (!targetCommit) { | ||
console.error('Error: specify a commit to search for as a command-line argument.'); | ||
process.exit(1); | ||
} | ||
|
||
// Enumerate matching tags and sort them in reverse order | ||
let tags: string[]; | ||
try { | ||
tags = execSync('git tag -l "v[0-9]*.[0-9]*.[0-9]*"') | ||
.toString() | ||
.trim() | ||
.split('\n') | ||
.sort((a: string, b: string) => { | ||
const parseVersion = (version: string) => { | ||
const [main, modifier] = version.slice(1).split('-'); | ||
const [major, minor, patch] = main.split('.').map(Number); | ||
return { major, minor, patch, modifier }; | ||
}; | ||
|
||
const aVersion = parseVersion(a); | ||
const bVersion = parseVersion(b); | ||
|
||
if (aVersion.major !== bVersion.major) { | ||
return bVersion.major - aVersion.major; | ||
} | ||
if (aVersion.minor !== bVersion.minor) { | ||
return bVersion.minor - aVersion.minor; | ||
} | ||
if (aVersion.patch !== bVersion.patch) { | ||
return bVersion.patch - aVersion.patch; | ||
} | ||
if (aVersion.modifier && bVersion.modifier) { | ||
return aVersion.modifier.localeCompare(bVersion.modifier); | ||
} | ||
return aVersion.modifier ? -1 : 1; | ||
}); | ||
} catch (error: any) { | ||
console.error(`Error fetching tags: ${error?.message}`); | ||
process.exit(1); | ||
} | ||
|
||
tags.forEach(tag => { | ||
// Extract cody.commit from gradle.properties for each tag | ||
let codyCommit; | ||
try { | ||
const gradleProperties = execSync(`git show ${tag}:gradle.properties`).toString(); | ||
const match = gradleProperties.match(/^cody\.commit=(.*)$/m); | ||
if (match) { | ||
codyCommit = match[1]; | ||
} else { | ||
console.log(`? ${tag}: No cody.commit found`); | ||
return; | ||
} | ||
} catch (error) { | ||
console.log(`? ${tag}: Error reading gradle.properties`); | ||
return; | ||
} | ||
|
||
// Fetch the relevant commit in the Cody repository | ||
try { | ||
execSync(`git -C ${CODY_DIR} fetch origin ${codyCommit}`, {stdio: 'ignore'}); | ||
} catch (error) { | ||
console.log(`? ${tag}: Error fetching commit ${codyCommit}`); | ||
return; | ||
} | ||
|
||
// Determine if the target commit is in the history of codyCommit | ||
try { | ||
execSync(`git -C ${CODY_DIR} merge-base --is-ancestor ${targetCommit} ${codyCommit}`); | ||
console.log(`✔️ ${tag}`); | ||
} catch (error: any) { | ||
if (error.status === 1) { | ||
// Exit code 1 means the target commit is not an ancestor | ||
console.log(`❌ ${tag}`); | ||
} else { | ||
// Any other error | ||
console.log(`? ${tag}: Error checking merge-base`); | ||
} | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"scripts": { | ||
"canhaz": "ts-node canhaz.ts" | ||
}, | ||
"type": "commonjs", | ||
"devDependencies": { | ||
"@types/node": "^22.7.2", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.6.2" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"outDir": "./dist", | ||
"rootDir": ".", | ||
"moduleResolution": "node", | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": ["node_modules/*"] | ||
} | ||
}, | ||
"include": ["canhaz.ts"], | ||
"exclude": ["node_modules"] | ||
} |