Skip to content

Commit

Permalink
Merge pull request SecureSECO#73 from gjgiezeman/main
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
slingerbv authored Oct 21, 2024
2 parents cf6b180 + 32174b4 commit d48db28
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:

# - name: Start the project
# run: npm run start-unix
- name: Make and install helper program
run: cd src/modules/searchSECO-crawler/cpp; make install; echo "$HOME/bin" >> "$GITHUB_PATH"

- name: Execute SearchSECO-miner check on zlib
env:
Expand Down
12 changes: 9 additions & 3 deletions src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,11 @@ export default abstract class Command {

if (metadata.defaultBranch !== this._flags.Branch)
await this._moduleFacade.SwitchVersion(this._flags.Branch);
const tags = await this._moduleFacade.GetRepositoryTags();
const tagc = tags.length;
//const tags = await this._moduleFacade.GetRepositoryTags();
//const tagc = tags.length;

await this.parseLatest(metadata, jobID, jobTime);
/*
if (metadata.versionTime > startingTime && tagc == 0) {
await this.parseLatest(metadata);
} else if (tagc != 0) {
Expand All @@ -256,6 +258,7 @@ export default abstract class Command {
}
await this.loopThroughTags(tags, metadata, startingTime, jobID, jobTime);
}
*/
}

/**
Expand Down Expand Up @@ -307,12 +310,15 @@ export default abstract class Command {
* Parse the latest version of a project
* @param metadata The metadata of the project
*/
private async parseLatest(metadata: ProjectMetadata) {
private async parseLatest(metadata: ProjectMetadata, jobID: string, jobTime: number) {
Logger.Debug('No tags found, just looking at HEAD', Logger.GetCallerLocation());
const [hashes, authorData] = await this.parseAndBlame();
if (hashes.length == 0) return;
Logger.Debug('Uploading hashes', Logger.GetCallerLocation());
await JsonRequest.UploadHashes(hashes, metadata, authorData, -1, []);
if (jobID != '') {
await JsonRequest.finishJob(jobID, jobTime, 0, '');
}
}

/**
Expand Down
31 changes: 30 additions & 1 deletion src/JsonRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ interface Upload {
method_data: MethodData[]
}

interface JobFinish {
jid: string,
time: number,
reason: number,
rdata: string
}


export type Task = "No" | { "Spider": SpiderTask } | { "Crawl": CrawlTask };

Expand All @@ -127,10 +134,12 @@ interface UpdateJobRequest { "UpdateJob": { "jid": string, "time": number } }

interface UploadRequest { "Upload": Upload }

interface FinishJobRequest { "FinishJob": JobFinish }

type Content =
CheckRequest | ProjectInfoRequest | AuthorRequest |
GetTaskRequest | CrawlJobsRequest | PrevProjectsRequest | UpdateJobRequest |
UploadRequest;
UploadRequest | FinishJobRequest;



Expand Down Expand Up @@ -167,6 +176,7 @@ export class JsonRequest {
Logger.Debug(`Status code: ${response.status}`, Logger.GetCallerLocation());

if (!response.ok) {
Logger.Warning(`JSON api status code: ${response.status}`, Logger.GetCallerLocation());
throw new Error(`Error! status: ${response.status}`);
}

Expand Down Expand Up @@ -365,6 +375,25 @@ export class JsonRequest {
}
}

public static async finishJob(jid: string, time: number, reason: number, rdata: string): Promise<number> {
let content = {
"FinishJob": { jid: jid, time: time, reason: reason, rdata: rdata }
};
try {
let obj = await this.PerformRequest(content);
return;
} catch (error) {
if (error instanceof Error) {
Logger.Warning(`error message: ${error.message}`, Logger.GetCallerLocation());
throw error;
} else {
Logger.Warning(`unexpected error: $error`, Logger.GetCallerLocation());
throw 'An unexpected error occurred';
}
}

}

}

function getAuthors(hashes: Map<string, HashData[]>, rawData: AuthorData): ObjectMap<HashData, Author[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/searchSECO-crawler

0 comments on commit d48db28

Please sign in to comment.