Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite052dbd

Browse files
committed
Remove caching mechanism
1 parent32795b3 commite052dbd

File tree

2 files changed

+23
-105
lines changed

2 files changed

+23
-105
lines changed

‎src/git-utils.test.ts‎

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -465,59 +465,7 @@ test("getGitVersionOrThrow throws when git command fails", async (t) => {
465465
}
466466
});
467467

468-
test("getGitVersion returns version and caches it",async(t)=>{
469-
gitUtils.resetCachedGitVersion();
470-
construnGitCommandStub=sinon
471-
.stub(gitUtilsasany,"runGitCommand")
472-
.resolves("git version 2.40.0\n");
473-
474-
constmessages:LoggedMessage[]=[];
475-
constlogger=getRecordingLogger(messages);
476-
477-
try{
478-
// First call should fetch and cache
479-
constversion1=awaitgitUtils.getGitVersion(logger);
480-
t.is(version1,"2.40.0");
481-
t.is(runGitCommandStub.callCount,1);
482-
483-
// Second call should use cache
484-
constversion2=awaitgitUtils.getGitVersion(logger);
485-
t.is(version2,"2.40.0");
486-
t.is(runGitCommandStub.callCount,1);// Should still be 1
487-
}finally{
488-
runGitCommandStub.restore();
489-
gitUtils.resetCachedGitVersion();
490-
}
491-
});
492-
493-
test("getGitVersion returns undefined when version cannot be determined",async(t)=>{
494-
gitUtils.resetCachedGitVersion();
495-
construnGitCommandStub=sinon
496-
.stub(gitUtilsasany,"runGitCommand")
497-
.rejects(newError("git not found"));
498-
499-
constmessages:LoggedMessage[]=[];
500-
constlogger=getRecordingLogger(messages);
501-
502-
try{
503-
constversion=awaitgitUtils.getGitVersion(logger);
504-
t.is(version,undefined);
505-
t.true(
506-
messages.some(
507-
(m)=>
508-
m.type==="debug"&&
509-
typeofm.message==="string"&&
510-
m.message.includes("Could not determine Git version"),
511-
),
512-
);
513-
}finally{
514-
runGitCommandStub.restore();
515-
gitUtils.resetCachedGitVersion();
516-
}
517-
});
518-
519468
test("gitVersionAtLeast returns true for version meeting requirement",async(t)=>{
520-
gitUtils.resetCachedGitVersion();
521469
construnGitCommandStub=sinon
522470
.stub(gitUtilsasany,"runGitCommand")
523471
.resolves("git version 2.40.0\n");
@@ -537,12 +485,10 @@ test("gitVersionAtLeast returns true for version meeting requirement", async (t)
537485
);
538486
}finally{
539487
runGitCommandStub.restore();
540-
gitUtils.resetCachedGitVersion();
541488
}
542489
});
543490

544491
test("gitVersionAtLeast returns false for version not meeting requirement",async(t)=>{
545-
gitUtils.resetCachedGitVersion();
546492
construnGitCommandStub=sinon
547493
.stub(gitUtilsasany,"runGitCommand")
548494
.resolves("git version 2.30.0\n");
@@ -555,12 +501,10 @@ test("gitVersionAtLeast returns false for version not meeting requirement", asyn
555501
t.false(result);
556502
}finally{
557503
runGitCommandStub.restore();
558-
gitUtils.resetCachedGitVersion();
559504
}
560505
});
561506

562507
test("gitVersionAtLeast returns false when version cannot be determined",async(t)=>{
563-
gitUtils.resetCachedGitVersion();
564508
construnGitCommandStub=sinon
565509
.stub(gitUtilsasany,"runGitCommand")
566510
.rejects(newError("git not found"));
@@ -581,6 +525,5 @@ test("gitVersionAtLeast returns false when version cannot be determined", async
581525
);
582526
}finally{
583527
runGitCommandStub.restore();
584-
gitUtils.resetCachedGitVersion();
585528
}
586529
});

‎src/git-utils.ts‎

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ import {
2323
*/
2424
exportconstGIT_MINIMUM_VERSION_FOR_OVERLAY="2.38.0";
2525

26-
/** Cached git version to avoid recomputing it multiple times. */
27-
letcachedGitVersion:string|undefined;
28-
29-
/**
30-
* Resets the cached git version. This is intended for use in tests only.
31-
*/
32-
exportfunctionresetCachedGitVersion():void{
33-
cachedGitVersion=undefined;
34-
}
35-
3626
/**
3727
* Gets the version of Git installed on the system and throws an error if
3828
* the version cannot be determined.
@@ -55,27 +45,6 @@ export async function getGitVersionOrThrow(): Promise<string> {
5545
thrownewError(`Could not parse Git version from output:${stdout.trim()}`);
5646
}
5747

58-
/**
59-
* Gets the cached Git version, or fetches and caches it if not yet cached.
60-
*
61-
*@param logger A logger to use for logging errors.
62-
*@returns The cached Git version, or undefined if the version could not be determined.
63-
*/
64-
exportasyncfunctiongetGitVersion(
65-
logger:Logger,
66-
):Promise<string|undefined>{
67-
if(cachedGitVersion!==undefined){
68-
returncachedGitVersion;
69-
}
70-
try{
71-
cachedGitVersion=awaitgetGitVersionOrThrow();
72-
returncachedGitVersion;
73-
}catch(e){
74-
logger.debug(`Could not determine Git version:${getErrorMessage(e)}`);
75-
returnundefined;
76-
}
77-
}
78-
7948
/**
8049
* Logs the Git version as a telemetry diagnostic. Should be called once during
8150
* initialization after the config is available.
@@ -87,19 +56,23 @@ export async function logGitVersionTelemetry(
8756
config:Config,
8857
logger:Logger,
8958
):Promise<void>{
90-
constversion=awaitgetGitVersion(logger);
91-
if(version!==undefined&&config.languages.length>0){
92-
addDiagnostic(
93-
config,
94-
// Arbitrarily choose the first language. We could also choose all languages, but that
95-
// increases the risk of misinterpreting the data.
96-
config.languages[0],
97-
makeTelemetryDiagnostic(
98-
"codeql-action/git-version-telemetry",
99-
"Git version telemetry",
100-
{gitVersion:version},
101-
),
102-
);
59+
try{
60+
constversion=awaitgetGitVersionOrThrow();
61+
if(config.languages.length>0){
62+
addDiagnostic(
63+
config,
64+
// Arbitrarily choose the first language. We could also choose all languages, but that
65+
// increases the risk of misinterpreting the data.
66+
config.languages[0],
67+
makeTelemetryDiagnostic(
68+
"codeql-action/git-version-telemetry",
69+
"Git version telemetry",
70+
{gitVersion:version},
71+
),
72+
);
73+
}
74+
}catch(e){
75+
logger.debug(`Could not determine Git version:${getErrorMessage(e)}`);
10376
}
10477
}
10578

@@ -115,12 +88,14 @@ export async function gitVersionAtLeast(
11588
requiredVersion:string,
11689
logger:Logger,
11790
):Promise<boolean>{
118-
constversion=awaitgetGitVersion(logger);
119-
if(version===undefined){
91+
try{
92+
constversion=awaitgetGitVersionOrThrow();
93+
logger.debug(`Installed Git version is${version}.`);
94+
returnsemver.gte(version,requiredVersion);
95+
}catch(e){
96+
logger.debug(`Could not determine Git version:${getErrorMessage(e)}`);
12097
returnfalse;
12198
}
122-
logger.debug(`Installed Git version is${version}.`);
123-
returnsemver.gte(version,requiredVersion);
12499
}
125100

126101
exportconstrunGitCommand=asyncfunction(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp