This repository was archived by the owner on Mar 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
fixes performance issues and output file #12
Open
tylerthehaas
wants to merge
31
commits into
lyqht:main
Choose a base branch
from
tylerthehaas:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a8b127f
add collectJsonStrings util
cf8db24
remove comments
e10c358
parallelize requesting string translation for each language
b684c12
adds buildOutputJson and writes to file for each language
f73d407
add a more robust speed test
tylerthehaas 6fabce7
add translateWithRetry with exponential back off
tylerthehaas b48146c
cleanup code comments
tylerthehaas 106af14
change return of translateText to return lang
tylerthehaas 7a34143
account for multiple requests for same language
tylerthehaas c1f6b83
update action name and author
tylerthehaas c2df7c8
fixes problem with keep tags being kept in output
tylerthehaas 170eb0c
2.2.1
tylerthehaas c6d903a
Added new `model_type` parameter that can be passed to the translateO…
joe-l-bd 968ef67
Update model type to 'prefer_quality_optimized' in main.ts and index.…
joe-l-bd cfa19cf
Update deepl-node dependency to version 1.22.0 and add tests for ES-4…
joe-l-bd 439e114
Refactor test assertions in main.test.ts for ES-419 translation to us…
joe-l-bd 2ba7b20
Merge pull request #1 from joe-l-bd/feat/add-model-type-param
tylerthehaas 22325e0
Add timeout input to action.yml and implement timeout handling in ind…
joe-l-bd 47088d7
Refactor timeout handling in index.ts by utilizing createTranslatorOp…
joe-l-bd 7668daa
add missing function
joe-l-bd 3e5ae71
Refactor createTranslatorOptions to accept timeout parameter and enha…
joe-l-bd ce98aff
Merge pull request #2 from joe-l-bd/feat/add-model-type-param
bit-tyler c6ecd1d
Translate only changed source segments and fix PR branch commits.
tylerthehaas 2fa7fd2
Allow workflows to pin the translation base branch.
tylerthehaas 1e0a2d3
Use the branch merge-base for incremental translations.
tylerthehaas a972ab8
Fetch the workflow repo base branch for merge-base diffing.
tylerthehaas 9dd2c67
fix review feedback
tylerthehaas 2b1c4bf
adds safe fallback
tylerthehaas 508a593
Add translateTexts function with unit tests for default and custom pr…
tylerthehaas 46e7dca
Enhance getTextLineMetadata function to handle empty lines and missin…
tylerthehaas 4b97a01
Merge pull request #3 from tylerthehaas/fix/incremental-pr-translation
bit-tyler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,108 @@ | ||
| import { execFile } from 'child_process' | ||
| import { promisify } from 'util' | ||
|
|
||
| const execFileAsync = promisify(execFile) | ||
|
|
||
| interface BaseFileContentParams { | ||
| workspacePath: string | ||
| inputFileRelativePath: string | ||
| baseRef?: string | ||
| } | ||
|
|
||
| function isMissingPathError(stderr: string) { | ||
| return ( | ||
| stderr.includes('exists on disk, but not in') || | ||
| stderr.includes('pathspec') || | ||
| stderr.includes('fatal: path') || | ||
| stderr.includes('does not exist') | ||
| ) | ||
| } | ||
|
|
||
| function getWorkflowRepositoryUrl(): string | null { | ||
| const serverUrl = process.env.GITHUB_SERVER_URL?.replace(/\/$/, '') | ||
| const repository = process.env.GITHUB_REPOSITORY | ||
|
|
||
| if (!serverUrl || !repository) { | ||
| return null | ||
| } | ||
|
|
||
| return `${serverUrl}/${repository}.git` | ||
| } | ||
|
|
||
| export async function getBaseFileContent({ | ||
| workspacePath, | ||
| inputFileRelativePath, | ||
| baseRef, | ||
| }: BaseFileContentParams): Promise<string | null> { | ||
| if (!baseRef) { | ||
| return null | ||
| } | ||
|
|
||
| const baseRepoUrl = getWorkflowRepositoryUrl() | ||
| const baseBranchRef = baseRepoUrl | ||
| ? `refs/remotes/base/${baseRef}` | ||
| : `refs/remotes/origin/${baseRef}` | ||
| const fetchSource = baseRepoUrl ?? 'origin' | ||
|
|
||
| try { | ||
| await execFileAsync( | ||
| 'git', | ||
| [ | ||
| 'fetch', | ||
| '--no-tags', | ||
| fetchSource, | ||
| `+refs/heads/${baseRef}:${baseBranchRef}`, | ||
| ], | ||
| { cwd: workspacePath, maxBuffer: 10 * 1024 * 1024 }, | ||
| ) | ||
| } catch (error) { | ||
| console.warn(`Failed to fetch base branch ${baseBranchRef}, falling back to local refs if available.`, error) | ||
| } | ||
|
|
||
| let baseCommitRef: string | null = null | ||
|
|
||
| try { | ||
| const { stdout } = await execFileAsync( | ||
| 'git', | ||
| ['merge-base', 'HEAD', baseBranchRef], | ||
| { cwd: workspacePath, maxBuffer: 10 * 1024 * 1024 }, | ||
| ) | ||
|
|
||
| const mergeBaseSha = stdout.trim() | ||
| if (mergeBaseSha) { | ||
| baseCommitRef = mergeBaseSha | ||
| } | ||
| } catch (error) { | ||
| console.warn( | ||
| `Failed to determine merge-base with ${baseBranchRef}, falling back to full translation.`, | ||
| error, | ||
| ) | ||
| } | ||
|
|
||
| if (!baseCommitRef) { | ||
| return null | ||
| } | ||
|
|
||
| try { | ||
| const normalizedInputFileRelativePath = inputFileRelativePath.replace(/\\/g, '/') | ||
| const { stdout } = await execFileAsync( | ||
| 'git', | ||
| ['show', `${baseCommitRef}:${normalizedInputFileRelativePath}`], | ||
| { cwd: workspacePath, maxBuffer: 10 * 1024 * 1024 }, | ||
| ) | ||
|
|
||
| return stdout | ||
| } catch (error) { | ||
| const stderr = error instanceof Error && 'stderr' in error ? String(error.stderr) : '' | ||
|
|
||
| if (isMissingPathError(stderr)) { | ||
| return null | ||
| } | ||
|
|
||
| console.warn( | ||
| `Failed to read ${inputFileRelativePath} from ${baseCommitRef}, falling back to full translation.`, | ||
| error, | ||
| ) | ||
| return null | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm o_O