Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist manifest information for sourcearchive components #625

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/cdConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ module.exports = {
format: '--json-pp'
},
source: {},
sourcearchive: {},
top: { githubToken }
},
store: {
Expand Down
1 change: 1 addition & 0 deletions providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
scancode: require('./process/scancode'),
fossology: require('./process/fossology'),
source: require('./process/source').processor,
sourcearchive: require('./process/sourcearchiveExtract'),
top: require('./process/top')
},
store: {
Expand Down
2 changes: 1 addition & 1 deletion providers/process/sourceExtract.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SourceExtract extends AbstractClearlyDefinedProcessor {

canHandle(request) {
const spec = this.toSpec(request)
return request.type === 'clearlydefined' && spec && ['git', 'sourcearchive'].includes(spec.type)
return request.type === 'clearlydefined' && spec && ['git'].includes(spec.type)
}

async handle(request) {
Expand Down
25 changes: 25 additions & 0 deletions providers/process/sourcearchiveExtract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

const AbstractClearlyDefinedProcessor = require('./abstractClearlyDefinedProcessor')
const { merge } = require('lodash')

class SourceArchiveExtract extends AbstractClearlyDefinedProcessor {
get toolVersion() {
return '1.2.0'
}

canHandle(request) {
const spec = this.toSpec(request)
return request.type === 'clearlydefined' && spec?.type === 'sourcearchive'
}

async handle(request) {
await super.handle(request)
const { summary, poms, releaseDate } = request.document
const manifest = { summary, poms }
request.document = merge(this.clone(request.document), { manifest, releaseDate })
}
}

module.exports = options => new SourceArchiveExtract(options)
52 changes: 52 additions & 0 deletions test/unit/providers/process/sourceArchiveExtractTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

const { expect } = require('chai')
const SourceArchiveExtract = require('../../../../providers/process/sourcearchiveExtract')
const Request = require('../../../../ghcrawler').request

const pomsArray = [{ pom1: 'pom1' }, { pom2: 'pom2' }]
const summaryObj = { version: '8.1.0' }

describe('SourceArchiveExtract Tests', () => {
let processor, request
beforeEach(async () => {
;({ processor, request } = await setup())
})

afterEach(() => {
request.getTrackedCleanups().forEach(cleanup => cleanup())
})

it('verifies the version of the source archive extract', () => {
expect(processor._schemaVersion).to.equal('1.4.0')
})

it('handles a source archive request', () => {
expect(processor.canHandle(request)).to.be.true
})

it('extracts the release date, summary and poms sections', async () => {
await processor.handle(request)
expect(request.document.manifest.summary).to.be.deep.equal(summaryObj)
expect(request.document.manifest.poms).to.be.deep.equal(pomsArray)
expect(request.document.releaseDate).to.be.equal('2021-08-01T00:00:00.000Z')
})
})

async function setup() {
const processor = SourceArchiveExtract({ logger: {} })
const request = createRequest()
const dir = processor.createTempDir(request)
request.document.location = dir.name
request.document.summary = { ...summaryObj }
request.document.poms = [...pomsArray]
request.document.releaseDate = '2021-08-01T00:00:00.000Z'
return { processor, request }
}

function createRequest() {
const request = new Request('clearlydefined', 'cd:/sourcearchive/mavencentral/org.osgi/osgi.annotation/8.1.0')
request.document = { _metadata: { links: {} }, registryData: { manifest: {} } }
return request
}
12 changes: 12 additions & 0 deletions test/unit/providers/process/sourceExtractTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// (c) Copyright 2024, SAP SE and ClearlyDefined contributors. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

const { expect } = require('chai')
const SourceExtract = require('../../../../providers/process/sourceExtract')

describe('SourceExtract', () => {
it('verifies version of the source extract', () => {
const handler = SourceExtract({})
expect(handler._schemaVersion).to.equal('1.3.0')
})
})
Loading