-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: copy across all ai-beta code (ca314fad)
- Loading branch information
0 parents
commit 03f98c7
Showing
1,028 changed files
with
82,541 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,100 @@ | ||
#.codiumai.toml | ||
[tests] | ||
|
||
## Testing framework to use - this can affect the content of the generated tests | ||
## as well as the test run command. | ||
## Possible values are: | ||
## Python: Pytest, Unittest | ||
## Javascript / Typescript: Jest, Mocha, Vitest, Karma, Jasmine, QUnit, React Testing Library | ||
## HOWEVER: running tests in JS / TS is at the moment only supported | ||
## for Jest, Mocha, Vitest, and React Testing Library | ||
framework = "Jest" | ||
|
||
## An additional Javascript utility library used to test your code, if any. | ||
## Possible values are None, Testing Library, Enzyme, or Chai. Not applicable to Python projects. | ||
# utility_library = "Testing Library" | ||
|
||
## A hint to the test generator about whether to use mocks or not. Possible values are true or false. | ||
use_mocks = true | ||
|
||
## How many tests should be generated by default. Fewer tests is faster. | ||
## Does not apply at the moment to extend-suite tests. | ||
# num_desired_tests = 6 | ||
|
||
## A multiline string, delimited with triple-quotes (""") serving as an extra instruction | ||
## that the AI model will take into consideration. | ||
## This will appear as "General instructions" in the | ||
## configuration section in the tests panel. | ||
# plan_instructions = """ | ||
# Each line should have a comment explaining it. | ||
# Each comment should start with the comment number (1., 2. etc.) | ||
# """ | ||
|
||
## A multiline string, delimited with triple-quotes (""") serving as an example test that represents | ||
## what you would like the generated tests to look like in terms of style, setup, etc. | ||
# example_test = """ | ||
# describe("something", () => { | ||
# it("says 'bar'", () => { | ||
# // given | ||
# | ||
# // when | ||
# const res = something.say(); | ||
# | ||
# // Then | ||
# expect(res).to.equal("bar"); | ||
# }); | ||
# }); | ||
# """ | ||
|
||
|
||
[tests.typescript] | ||
|
||
## When running Javascript / Typescript tests, use this directory as the test process "current working directory". | ||
## This is a path relative to the location of the config file. | ||
## Default: The directory containing the config file. | ||
## Note: the typical setup is to place the config file in the same directory as the relevant 'package.json' file, | ||
## and leave this commented-out. | ||
# overrideTestRunCwd = "./test" | ||
|
||
## This is the command that's used to run tests. | ||
## PLEASE READ CAREFULLY: | ||
## | ||
## When running tests, CodiumAI generates a temporary file that contains the test code for a single test, | ||
## and runs that file. | ||
## When the tests are done, the temporary file is deleted. | ||
## For component-oriented tests (when you click "test this class" or "test this function"), the temporary file | ||
## is created next to the file being tested. | ||
## For extend-suite tests (when you click "add more tests" on a test-suite), the temporary file is created next | ||
## to the test-suite file. | ||
## | ||
## Typically, you're going to want to take the test script defined in your package.json file, and tweak it a | ||
## little to make it compatible with CodiumAI. | ||
## | ||
## You almost always want to start with 'npx' (e.g. 'npx jest', not 'npm jest' or 'yarn test'). | ||
## | ||
## Note that the test command must be able to run test files that are located in the same directory as the | ||
## file under test. | ||
## A common issue is that the test command in the package.json file selects only from | ||
## a "tests" directory, causing the CodiumAI tests be "not found" - please remove any such restriction from | ||
## the command / configuration. | ||
## | ||
## The placeholder TEST_FILEPATH will be replaced with the actual test file path - this is how we find | ||
## the file to run. | ||
## | ||
## EXAMPLES: | ||
## Mocha: | ||
## npx ts-mocha TEST_FILEPATH --require ./test/mocha/setup.ts | ||
## Jest: | ||
## npx jest --runTestsByPath TEST_FILEPATH | ||
## | ||
## DEBUGGING NOTE: | ||
## To help debug run-tests issues, you can view run logs in vscode's OUTPUT | ||
## (select codium-ai from the dropdown). | ||
## It's helpful to clear the output (right-click -> clear) and then run the tests again. | ||
## | ||
overrideTestRunScript = "pnpm test --" | ||
|
||
## A multiline string, delimited with triple-quotes ("""), | ||
## containing import declaration to use in each test file. | ||
# overrideImports = """ | ||
# import {expect} from 'chai'; """ |
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,15 @@ | ||
/** @type {import("eslint").Linter.Config} */ | ||
module.exports = { | ||
root: true, | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: [ | ||
"./tsconfig.json", | ||
"./apps/*/tsconfig.json", | ||
"./packages/*/tsconfig.json", | ||
], | ||
}, | ||
plugins: ["@typescript-eslint"], | ||
extends: ["plugin:@typescript-eslint/recommended"], | ||
}; |
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,43 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: "" | ||
labels: bug | ||
assignees: "" | ||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
|
||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Logs** | ||
Please provide logs showing the error. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information):** | ||
|
||
- OS: [e.g. iOS] | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Smartphone (please complete the following information):** | ||
|
||
- Device: [e.g. iPhone6] | ||
- OS: [e.g. iOS8.1] | ||
- Browser [e.g. stock browser, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
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,16 @@ | ||
name: "Get branch Ref from SHA" | ||
description: "Given a SHA, find a PR with a matching head, else check head of `main`, and return the ref." | ||
inputs: | ||
github_token: | ||
description: "A Github token, e.g. secrets.GITHUB_TOKEN" | ||
required: true | ||
outputs: | ||
branch_name: | ||
description: "The *branch name* (e.g. feature/new_buttons) of the PR source branch with the SHA as the head commit, or branch if there is no PR (typically 'main')" | ||
head_ref: | ||
description: "The *ref* (e.g. refs/heads/feature/new_buttons) of the PR source branch with the SHA as the head commit, or branch if there is no PR (typically 'main')" | ||
pr_number: | ||
description: "The number of the PR if one is found" | ||
runs: | ||
using: "node20" | ||
main: "index.js" |
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,36 @@ | ||
/** | ||
* Given repo info and a sha, get first branch that sha is the current head of (prefer `main`), or null. | ||
* | ||
* @param {Object} octokit a pre-authed instance of Octokit | ||
* @param {Object} repoInfo repo information | ||
* @param {string} sha commit sha | ||
* | ||
* @returns {Object|null} The matched branch, or null. | ||
*/ | ||
async function branchFromSha(octokit, repoInfo, sha) { | ||
// https://octokit.github.io/rest.js/v18 | ||
const { data: branches } = await octokit.rest.repos.listBranchesForHeadCommit( | ||
{ | ||
...repoInfo, | ||
commit_sha: sha, | ||
}, | ||
); | ||
|
||
// No matching branches. | ||
if (!branches || branches.length === 0) { | ||
return null; | ||
} | ||
|
||
const main = branches.find((branch) => branch.name === "main"); | ||
if (main) { | ||
// It's the HEAD SHA of the main branch. | ||
return main; | ||
} else { | ||
// It's the HEAD SHA of _a_ branch, we don't know which one we care about, return the first one. | ||
// This should rarely happen (maybe a CI run on a branch that ins't in a PR), and then the chance | ||
// of there being two branches with the same HEAD are very low. | ||
return branches[0]; | ||
} | ||
} | ||
|
||
module.exports = branchFromSha; |
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,70 @@ | ||
/** | ||
* Given the GITHUB_SHA, find the pr and ref it is the head of. | ||
* | ||
* Intended for use with Vercel `deployment_status` events which incorrectly | ||
* set the GITHUB_REF to the commit SHA value. | ||
*/ | ||
|
||
const core = require("@actions/core"); | ||
const github = require("@actions/github"); | ||
|
||
const prFromSha = require("./pr_from_sha"); | ||
const branchFromSha = require("./branch_from_sha"); | ||
|
||
async function run() { | ||
try { | ||
const githubToken = core.getInput("github_token"); | ||
|
||
const octokit = github.getOctokit(githubToken); | ||
|
||
const owner = github.context.payload.repository.owner.login; | ||
const repo = github.context.payload.repository.name; | ||
if (!owner || !repo) { | ||
throw new Error( | ||
`Could not determine repo details, got: owner "${owner} and repo "${repo}".`, | ||
); | ||
} | ||
|
||
let sha = github.context.sha; | ||
if (!sha) { | ||
throw new Error(`SHA not supplied.`); | ||
} | ||
|
||
// Get the *first* PR that has the given SHA as the head of the feature branch. | ||
const pullRequest = await prFromSha(octokit, { owner, repo }, sha); | ||
let headRef; | ||
let prNumber = undefined; | ||
if (pullRequest !== null) { | ||
// There is a PR with this SHA as the head of the feature branch | ||
headRef = pullRequest.head.ref; | ||
// DEBUG | ||
core.debug(`Pull Request:\n${JSON.stringify(pullRequest, null, 2)}`); | ||
prNumber = pullRequest.number; | ||
} else { | ||
// The SHA is not on a PR feature branch, get from first matching general branch, prefer `main`. | ||
const branch = await branchFromSha(octokit, { owner, repo }, sha); | ||
if (branch !== null) { | ||
headRef = branch.name; | ||
} else { | ||
// No refs to be had. | ||
core.error(`Could not find pull request or branch for SHA: ${sha}`); | ||
} | ||
} | ||
|
||
/** @todo handle release tags? v1.2.3 */ | ||
const fullHeadRef = `refs/heads/${headRef}`; | ||
core.setOutput("branch_name", headRef); | ||
core.setOutput("head_ref", fullHeadRef); | ||
core.setOutput("pr_number", prNumber); | ||
core.info( | ||
`Found pull request or branch for for SHA: ${sha} with ref: ${fullHeadRef}.${ | ||
prNumber ? `Found PR number: ${prNumber}` : "" | ||
}`, | ||
); | ||
} catch (error) { | ||
core.error(error); | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
run(); |
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,30 @@ | ||
/** | ||
* Given repo info and a sha, get the pull request that sha is the current head of, or null. | ||
* | ||
* @param {Object} octokit a pre-authed instance of Octokit | ||
* @param {Object} repoInfo repo information | ||
* @param {string} sha commit sha | ||
* | ||
* @returns {Object|null} The matched PR, or null. | ||
*/ | ||
async function prFromSha(octokit, repoInfo, sha) { | ||
// https://octokit.github.io/rest.js/v18 | ||
// https://docs.github.com/en/rest/reference/pulls#list-pull-requests | ||
const { data: pullRequests } = await octokit.rest.pulls.list({ | ||
sort: "updated", | ||
direction: "desc", | ||
...repoInfo, | ||
}); | ||
|
||
return ( | ||
pullRequests.find((pr) => { | ||
const prHeadSha = pr.head.sha; | ||
if (typeof prHeadSha !== "string") { | ||
return false; | ||
} | ||
return prHeadSha.startsWith(sha); | ||
}) || null | ||
); | ||
} | ||
|
||
module.exports = prFromSha; |
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,45 @@ | ||
const github = require("@actions/github"); | ||
|
||
const prFromSha = require("../pr_from_sha"); | ||
const branchFromSha = require("../branch_from_sha"); | ||
|
||
const githubToken = process.env.GITHUB_TOKEN; | ||
|
||
if (!githubToken) { | ||
throw new Error("Need Github token"); | ||
} | ||
const octokit = github.getOctokit(githubToken); | ||
|
||
const owner = github.context.payload.repository.owner.login; | ||
const repo = github.context.payload.repository.name; | ||
if (!owner || !repo) { | ||
throw new Error( | ||
`Could not determine repo details, got: owner "${owner} and repo "${repo}".`, | ||
); | ||
} | ||
|
||
const repoInfo = { | ||
owner, | ||
repo, | ||
}; | ||
|
||
// PR test | ||
// Set this to the head commit on a branch in a PR, short SHAs are fine. | ||
const prSha = "c6458f3"; | ||
prFromSha(octokit, repoInfo, prSha).then((pr) => { | ||
if (pr === null) { | ||
console.log("no pr found"); | ||
} else { | ||
console.log(pr.head.ref); | ||
} | ||
}); | ||
|
||
// branch test | ||
const branchPr = "5c34737740d989b05d021769871dd1a365ded88d"; | ||
branchFromSha(octokit, repoInfo, branchPr).then((branch) => { | ||
if (branch === null) { | ||
console.log("no branch found"); | ||
} else { | ||
console.log(branch); | ||
} | ||
}); |
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,27 @@ | ||
## Description | ||
|
||
- List of changes | ||
|
||
## Issue(s) | ||
|
||
Fixes # | ||
|
||
## How to test | ||
|
||
1. Go to {deployment_url} | ||
2. Click on \_\_\_\_\_\_ | ||
3. You should see \_\_\_\_\_\_ | ||
|
||
## Screenshots | ||
|
||
How it used to look (delete if n/a): | ||
{screenshots} | ||
|
||
How it should now look: | ||
{screenshots} | ||
|
||
## Checklist | ||
|
||
- [ ] Manually tested across browsers / devices | ||
- [ ] Considered impact on accessibility | ||
- [ ] Does this PR update a package with a breaking change |
Oops, something went wrong.