Skip to content

Commit 78beccb

Browse files
Shared tsconfig.json & update options (#29)
* Update TypeScript configuration from leanix-sandbox:mob/main * Fix optional chaining in hunk reader and enforce non-null assertions in main * Update TypeScript configuration from leanix-sandbox:mob/main * Enforce non-null assertions for actionYaml inputs and regex match groups * Use shared tsconfig * Fix optional chaining for actionYaml input defaults in development environment * Add composite option to tsconfig files and update references * Remove composite option from pr-review and pr-summary tsconfig files; add it to the main tsconfig * Add property to pr-review and pr-summary tsconfig files
1 parent 11a6bb8 commit 78beccb

File tree

16 files changed

+293
-40
lines changed

16 files changed

+293
-40
lines changed

pr-review/dist/ai-core-client.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ChatMessage } from "@sap-ai-sdk/orchestration";
2+
import { z } from "zod";
3+
export declare function getModelName(): string;
4+
export declare function getPromptTokens(): number;
5+
export declare function getCompletionTokens(): number;
6+
/**
7+
* Create a simple chat completion.
8+
*/
9+
export declare function chatCompletion(messages: ChatMessage[]): Promise<string>;
10+
/**
11+
* Create a chat completion that returns a JSON document with a given schema.
12+
*/
13+
export declare function chatCompletionWithJsonSchema<T extends z.ZodTypeAny>(zodSchema: T, messages: ChatMessage[]): Promise<z.infer<T>>;

pr-review/dist/config.d.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* The configuration for the action.
3+
*/
4+
export declare const config: {
5+
/** The personal access token of the GitHub user that is used to create the review. */
6+
userToken: string;
7+
/** The URL for GitHub REST API */
8+
githubApiUrl: string;
9+
/** The owner of the repository for which the review should be created. */
10+
owner: string;
11+
/** The name of the repository for which the review should be created. */
12+
repo: string;
13+
/** The number of the pull request for which the review should be created. */
14+
prNumber: number;
15+
/** The hash of the commit representing the code before changes. Used as the starting point in comparison. */
16+
baseSha: string;
17+
/** The hash of the commit representing the code after changes. Used as the end point in comparison. */
18+
headSha: string;
19+
/** The service key for your SAP AI Core service instance. */
20+
aicoreServiceKey: {
21+
[x: string]: any;
22+
clientid: string;
23+
clientsecret: string;
24+
serviceurls: {
25+
[x: string]: any;
26+
AI_API_URL: string;
27+
};
28+
url: string;
29+
};
30+
/** A list of patterns that match the files that should be included in the review. */
31+
includeFiles: string[];
32+
/** A list of patterns that match the files that should be excluded from the review. */
33+
excludeFiles: string[];
34+
/** A list of patterns for files that should always be included as context, regardless of whether the PR affects them. */
35+
includeContextFiles: string[];
36+
/** A list of patterns for files that should be excluded from context, regardless of whether the PR affects them. */
37+
excludeContextFiles: string[];
38+
/** The name of the SAP AI Core model that is used to generate the review. */
39+
model: import("@sap-ai-sdk/orchestration").ChatModel;
40+
/** Additional parameters for the model as JSON. For example, {"temperature": 0.5, "max_tokens": 100}. */
41+
modelParameters: import("@sap-ai-sdk/orchestration").LlmModelParams;
42+
/** The version of the model that is used to generate the review. */
43+
modelVersion: string;
44+
/** The deployment configuration as JSON. For example, {"resourceGroup": "abcdefg"}. */
45+
deploymentConfig: import("@sap-ai-sdk/ai-api").ResourceGroupConfig;
46+
/** Whether to show the model metadata in the footer of the review. */
47+
showModelMetadataFooter: boolean;
48+
/** The base prompt that is used to generate the review. */
49+
prompt: string;
50+
/** Defines where the review will be posted. */
51+
displayMode: "review-comment" | "review-comment-delta" | "none";
52+
/** The prompt to use for the disclaimer. */
53+
disclaimerPrompt: string;
54+
/** The text that is placed before the review. */
55+
headerText: string;
56+
/** The text that is placed after the review. */
57+
footerText: string;
58+
/** The action to take with previous results. */
59+
previousResults: "keep" | "hide";
60+
/** Additional prompt text that is added to the base prompt. */
61+
promptAddition: string;
62+
};
63+
export type Config = typeof config;

pr-review/dist/hunk-reader.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { RestEndpointMethodTypes } from "@octokit/action";
2+
import { File } from "parse-diff";
3+
import { AiReview } from "./review.js";
4+
export type ReviewComment = Exclude<RestEndpointMethodTypes["pulls"]["createReview"]["parameters"]["comments"], undefined>[number];
5+
/** Because GitHub comments referencing a diff need to reference lines of the same hunk, we add/collect some metadata to find the corresponding hunk after AI processing */
6+
export declare function helpAIwithHunksInDiff(file: File): string;
7+
/** Map comments from the AI model to GitHub review comments and take care that a comment references only one single hunk */
8+
export declare function resolveHunkReferencesInComments(comments: AiReview["comments"], files: File[]): ReviewComment[];

pr-review/dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

pr-review/dist/index.js

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -100956,7 +100956,7 @@ if (process.env.NODE_ENV === "development") {
100956100956
// eslint-disable-next-line @typescript-eslint/no-for-in-array, no-restricted-syntax, guard-for-in
100957100957
for (const key in actionYaml.inputs) {
100958100958
const envKey = `INPUT_${key.toUpperCase()}`;
100959-
const envValue = actionYaml.inputs[key].default;
100959+
const envValue = actionYaml.inputs[key]?.default;
100960100960
if (envValue && !Object.keys(process.env).includes(envKey)) {
100961100961
process.env[envKey] = envValue;
100962100962
}
@@ -116618,46 +116618,53 @@ function resolveHunkReferencesInComments(comments, files) {
116618116618
}
116619116619
else {
116620116620
const hunkChangeMap = currentFile.chunks.flatMap(hunk => hunk.changes.map(change => ({ change, hunk })));
116621-
let { change: startChange, hunk: startHunk } = hunkChangeMap[comment.start - 1]; // eslint-disable-line prefer-const
116622-
let { change: endChange, hunk: endHunk } = hunkChangeMap[comment.end - 1]; // eslint-disable-line prefer-const
116623-
if (!startHunk) {
116624-
lib_core.warning(`Could not find hunk for comment on ${comment.path}, start ${comment.start}, end ${comment.end}, ${comment.comment}, skipping.`);
116621+
const startEntry = hunkChangeMap[comment.start - 1];
116622+
const endEntry = hunkChangeMap[comment.end - 1];
116623+
if (!startEntry || !endEntry) {
116624+
lib_core.error(`Could not find hunk for comment on ${comment.path}, start ${comment.start}, end ${comment.end}, ${comment.comment}, skipping.`);
116625116625
}
116626116626
else {
116627-
if (startHunk !== endHunk)
116628-
endChange = startHunk.changes.at(-1);
116629-
const startSide = startChange.type !== "del" ? "RIGHT" : "LEFT";
116630-
const endSide = endChange.type !== "del" ? "RIGHT" : "LEFT";
116631-
// get start line of the actual comment
116632-
let start;
116633-
if (startChange.type === "normal") {
116634-
start = startChange.ln2;
116627+
const { change: startChange, hunk: startHunk } = startEntry;
116628+
let { change: endChange, hunk: endHunk } = endEntry; // eslint-disable-line prefer-const
116629+
if (!startHunk) {
116630+
lib_core.warning(`Could not find hunk for comment on ${comment.path}, start ${comment.start}, end ${comment.end}, ${comment.comment}, skipping.`);
116635116631
}
116636-
else if (startChange.type === "add" || startChange.type === "del") {
116637-
start = startChange.ln;
116638-
}
116639-
else
116640-
throw new Error(`Unknown change type.`);
116641-
// get end line of the actual comment
116642-
let end;
116643-
if (endChange.type === "normal") {
116644-
end = endChange.ln2;
116645-
}
116646-
else if (endChange.type === "add" || endChange.type === "del") {
116647-
end = endChange.ln;
116632+
else {
116633+
if (startHunk !== endHunk)
116634+
endChange = startHunk.changes.at(-1);
116635+
const startSide = startChange.type !== "del" ? "RIGHT" : "LEFT";
116636+
const endSide = endChange.type !== "del" ? "RIGHT" : "LEFT";
116637+
// get start line of the actual comment
116638+
let start;
116639+
if (startChange.type === "normal") {
116640+
start = startChange.ln2;
116641+
}
116642+
else if (startChange.type === "add" || startChange.type === "del") {
116643+
start = startChange.ln;
116644+
}
116645+
else
116646+
throw new Error(`Unknown change type.`);
116647+
// get end line of the actual comment
116648+
let end;
116649+
if (endChange.type === "normal") {
116650+
end = endChange.ln2;
116651+
}
116652+
else if (endChange.type === "add" || endChange.type === "del") {
116653+
end = endChange.ln;
116654+
}
116655+
else
116656+
throw new Error(`Unknown change type.`);
116657+
// make sure start and end are within the hunk
116658+
end = Math.min(end, endSide === "RIGHT" ? startHunk.newStart + startHunk.newLines - 1 : startHunk.oldStart + startHunk.oldLines - 1);
116659+
result.push({
116660+
path: comment.path,
116661+
start_side: startSide !== endSide ? startSide : undefined, // only set start_side if it is a multi-line comment
116662+
side: startSide !== endSide ? endSide : startSide,
116663+
start_line: start !== end && start < end ? start : undefined, // only set start_line if it is a multi-line comment, start must be less than end
116664+
line: start !== end && start < end ? end : start,
116665+
body: comment.comment,
116666+
});
116648116667
}
116649-
else
116650-
throw new Error(`Unknown change type.`);
116651-
// make sure start and end are within the hunk
116652-
end = Math.min(end, endSide === "RIGHT" ? startHunk.newStart + startHunk.newLines - 1 : startHunk.oldStart + startHunk.oldLines - 1);
116653-
result.push({
116654-
path: comment.path,
116655-
start_side: startSide !== endSide ? startSide : undefined, // only set start_side if it is a multi-line comment
116656-
side: startSide !== endSide ? endSide : startSide,
116657-
start_line: start !== end && start < end ? start : undefined, // only set start_line if it is a multi-line comment, start must be less than end
116658-
line: start !== end && start < end ? end : start,
116659-
body: comment.comment,
116660-
});
116661116668
}
116662116669
}
116663116670
});

pr-review/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pr-review/dist/main.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Config } from "./config.js";
2+
/**
3+
* The main function for the action.
4+
* @returns {Promise<void>} Resolves when the action is complete.
5+
*/
6+
export declare function run(config: Config): Promise<void>;

pr-review/dist/review.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { z } from "zod";
2+
export declare const AiReview: z.ZodObject<{
3+
comments: z.ZodArray<z.ZodObject<{
4+
path: z.ZodString;
5+
comment: z.ZodString;
6+
start: z.ZodNumber;
7+
end: z.ZodNumber;
8+
}, z.core.$strip>>;
9+
}, z.core.$strip>;
10+
export type AiReview = z.infer<typeof AiReview>;

pr-review/dist/zod-schema.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { ResourceGroupConfig } from "@sap-ai-sdk/ai-api";
2+
import { ChatModel, LlmModelParams } from "@sap-ai-sdk/orchestration";
3+
import { z, ZodType } from "zod";
4+
export declare const ServiceKey: z.ZodObject<{
5+
clientid: z.ZodString;
6+
clientsecret: z.ZodString;
7+
serviceurls: z.ZodObject<{
8+
AI_API_URL: z.ZodString;
9+
}, z.core.$catchall<z.ZodAny>>;
10+
url: z.ZodString;
11+
}, z.core.$catchall<z.ZodAny>>;
12+
export type ServiceKey = z.infer<typeof ServiceKey>;
13+
export declare const ServiceKeyOrCredentials: z.ZodUnion<readonly [z.ZodObject<{
14+
clientid: z.ZodString;
15+
clientsecret: z.ZodString;
16+
serviceurls: z.ZodObject<{
17+
AI_API_URL: z.ZodString;
18+
}, z.core.$catchall<z.ZodAny>>;
19+
url: z.ZodString;
20+
}, z.core.$catchall<z.ZodAny>>, z.ZodObject<{
21+
credentials: z.ZodObject<{
22+
clientid: z.ZodString;
23+
clientsecret: z.ZodString;
24+
serviceurls: z.ZodObject<{
25+
AI_API_URL: z.ZodString;
26+
}, z.core.$catchall<z.ZodAny>>;
27+
url: z.ZodString;
28+
}, z.core.$catchall<z.ZodAny>>;
29+
}, z.core.$strip>]>;
30+
export type ServiceKeyOrCredentials = z.infer<typeof ServiceKeyOrCredentials>;
31+
export declare const ModelName: ZodType<ChatModel>;
32+
export type ModelName = z.infer<typeof ModelName>;
33+
export declare const DeploymentConfig: ZodType<ResourceGroupConfig>;
34+
export type DeploymentConfig = z.infer<typeof DeploymentConfig>;
35+
export declare const ModelParameters: ZodType<LlmModelParams>;
36+
export type ModelParameters = z.infer<typeof ModelParameters>;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ChatMessage } from "@sap-ai-sdk/orchestration";
2+
export declare function getModelName(): string;
3+
export declare function getPromptTokens(): number;
4+
export declare function getCompletionTokens(): number;
5+
export declare function chatCompletion(messages: ChatMessage[]): Promise<string>;

0 commit comments

Comments
 (0)