Skip to content

Commit

Permalink
fix: download artifacts from unmerged-lane-id when applicable (#6537)
Browse files Browse the repository at this point in the history
When an artifacts is needed, Bit goes to the lane-remote or main-remote depends whether this version is on the lane.
In case a component is during merge, its aspects config/data consist of both: the current version and the merged version, as such, it's hard to know where to get the artifacts from. the current-version scope or the merged-version scope.
This PR attempts to go to the merged-scope first, and then to the current-version scope.
  • Loading branch information
davidfirst authored Oct 12, 2022
1 parent 6728a58 commit c29c29f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/consumer/component/sources/artifact-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,32 @@ export class ArtifactFiles {
const allHashes = this.refs.map((artifact) => artifact.ref.hash);
const scopeComponentsImporter = ScopeComponentsImporter.getInstance(scope);
const lane = await scope.getCurrentLaneObject();
const unmergedEntry = scope.objects.unmergedComponents.getEntry(id.name);
let errorFromUnmergedLaneScope: Error | undefined;
if (unmergedEntry?.laneId) {
try {
logger.debug(
`getVinylsAndImportIfMissing, trying to get artifacts for ${id.toString()} from unmerged-lane-id: ${unmergedEntry.laneId.toString()}`
);
await scopeComponentsImporter.importManyObjects({ [unmergedEntry.laneId.scope]: allHashes });
} catch (err: any) {
logger.debug(
`getVinylsAndImportIfMissing, unable to get artifacts for ${id.toString()} from ${unmergedEntry.laneId.toString()}`
);
errorFromUnmergedLaneScope = err;
}
}
const isIdOnLane = await scope.isIdOnLane(id, lane);
const scopeName = isIdOnLane ? (lane?.scope as string) : (id.scope as string);
await scopeComponentsImporter.importManyObjects({ [scopeName]: allHashes });
try {
await scopeComponentsImporter.importManyObjects({ [scopeName]: allHashes });
} catch (err) {
if (!unmergedEntry || errorFromUnmergedLaneScope) {
logger.error('failed fetching the following hashes', { id, isIdOnLane, scopeName, allHashes });
throw err;
}
// unmergedEntry is set, and it was able to fetch from the unmerged-lane-id scope. all is good.
}
const getOneArtifact = async (artifact: ArtifactRef) => {
const content = (await artifact.ref.load(scope.objects)) as Source;
if (!content) throw new ShowDoctorError(`failed loading file ${artifact.relativePath} from the model`);
Expand Down

0 comments on commit c29c29f

Please sign in to comment.