Skip to content

Commit f408fd2

Browse files
authored
Merge pull request #572 from clearlydefined/master
Merge `master` into `prod` for release `v1.0.2`
2 parents 5465642 + 63526a8 commit f408fd2

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clearlydefined-crawler",
3-
"version": "0.1.1",
3+
"version": "1.0.2",
44
"description": "A crawler that walks projects and packages looking for data of interest to the ClearlyDefined project.",
55
"main": "./index.js",
66
"scripts": {

providers/fetch/gitCloner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { clone } = require('lodash')
77
const rimraf = require('rimraf')
88
const FetchResult = require('../../lib/fetchResult')
99

10-
const providerDictionary = {
10+
const providerMap = {
1111
gitlab: 'https://gitlab.com',
1212
github: 'https://github.com'
1313
}
@@ -95,7 +95,7 @@ class GitCloner extends AbstractFetch {
9595

9696
_buildUrl(spec) {
9797
const fullName = `${spec.namespace.replace(/\./g, '/')}/${spec.name}`
98-
return `${providerDictionary[spec.provider]}/${fullName}.git`
98+
return `${providerMap[spec.provider]}/${fullName}.git`
9999
}
100100
}
101101

providers/fetch/goFetch.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const { parse: htmlParser } = require('node-html-parser')
99
const { parse: spdxParser } = require('@clearlydefined/spdx')
1010
const FetchResult = require('../../lib/fetchResult')
1111

12+
const providerMap = {
13+
golang: 'https://proxy.golang.org'
14+
}
15+
1216
class GoFetch extends AbstractFetch {
1317
constructor(options) {
1418
super(options)
@@ -69,7 +73,7 @@ class GoFetch extends AbstractFetch {
6973
}
7074

7175
async _getLatestVersion(spec) {
72-
const initial_url = `https://${spec.provider}/${spec.namespace}/${spec.name}/@v/list`
76+
const initial_url = `${providerMap.golang}/${spec.namespace}/${spec.name}/@v/list`
7377
const replace_encoded_url = this._replace_encodings(initial_url)
7478
const url = replace_encoded_url.replace(/null\//g, '')
7579

@@ -89,7 +93,7 @@ class GoFetch extends AbstractFetch {
8993
}
9094

9195
_buildUrl(spec, extension = '.zip') {
92-
let initial_url = `https://proxy.golang.org/${spec.namespace}/${spec.name}/@v/${spec.revision}${extension}`
96+
let initial_url = `${providerMap.golang}/${spec.namespace}/${spec.name}/@v/${spec.revision}${extension}`
9397
return this._replace_encodings(this._remove_blank_fields(initial_url))
9498
}
9599

test/unit/providers/fetch/goFetchTests.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ const Request = require('../../../../ghcrawler').request
99
const fs = require('fs')
1010
const { merge } = require('lodash')
1111

12-
const stub = 'https://proxy.golang.org/'
12+
const goBaseURL = 'https://proxy.golang.org/'
1313

1414
describe('Go utility functions', () => {
1515
it('builds URLs', () => {
1616
const fetch = GoFetch({})
17-
expect(fetch._buildUrl(spec('go', 'golang', 'cloud.google.com', 'go', 'v0.56.0'))).to.equal(stub + 'cloud.google.com/go/@v/v0.56.0.zip')
18-
expect(fetch._buildUrl(spec('go', 'golang', 'cloud.google.com', 'go', 'v0.56.0'), '.mod')).to.equal(stub + 'cloud.google.com/go/@v/v0.56.0.mod')
19-
expect(fetch._buildUrl(spec('go', 'golang', '-', 'collectd.org', 'v0.5.0'))).to.equal(stub + 'collectd.org/@v/v0.5.0.zip')
20-
expect(fetch._buildUrl(spec('go', 'golang', 'github.com%2fAzure%2fazure-event-hubs-go', 'v3', 'v3.2.0'))).to.equal(stub + 'github.com/Azure/azure-event-hubs-go/v3/@v/v3.2.0.zip')
21-
expect(fetch._buildUrl(spec('go', 'golang', 'github.com%2FAzure%2Fazure-event-hubs-go', 'v3', 'v3.2.0'))).to.equal(stub + 'github.com/Azure/azure-event-hubs-go/v3/@v/v3.2.0.zip')
17+
expect(fetch._buildUrl(spec('go', 'golang', 'cloud.google.com', 'go', 'v0.56.0'))).to.equal(goBaseURL + 'cloud.google.com/go/@v/v0.56.0.zip')
18+
expect(fetch._buildUrl(spec('go', 'golang', 'cloud.google.com', 'go', 'v0.56.0'), '.mod')).to.equal(goBaseURL + 'cloud.google.com/go/@v/v0.56.0.mod')
19+
expect(fetch._buildUrl(spec('go', 'golang', '-', 'collectd.org', 'v0.5.0'))).to.equal(goBaseURL + 'collectd.org/@v/v0.5.0.zip')
20+
expect(fetch._buildUrl(spec('go', 'golang', 'github.com%2fAzure%2fazure-event-hubs-go', 'v3', 'v3.2.0'))).to.equal(goBaseURL + 'github.com/Azure/azure-event-hubs-go/v3/@v/v3.2.0.zip')
21+
expect(fetch._buildUrl(spec('go', 'golang', 'github.com%2FAzure%2Fazure-event-hubs-go', 'v3', 'v3.2.0'))).to.equal(goBaseURL + 'github.com/Azure/azure-event-hubs-go/v3/@v/v3.2.0.zip')
2222
})
2323
})
2424

@@ -47,6 +47,7 @@ describe('Go Proxy fetching', () => {
4747
beforeEach(() => {
4848
const requestPromiseStub = options => {
4949
if (options.url) {
50+
expect(options.url).to.contain(goBaseURL)
5051
if (options.url.includes('error')) throw new Error('yikes')
5152
if (options.url.includes('code')) throw { statusCode: 500, message: 'Code' }
5253
if (options.url.includes('missing')) throw { statusCode: 404 }

0 commit comments

Comments
 (0)