This repository has been archived by the owner on May 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): fetch and return last version git head sha
- Loading branch information
1 parent
9afc4e6
commit a393b0e
Showing
10 changed files
with
283 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Dependencies | ||
*/ | ||
|
||
import SemanticReleaseError from '@semantic-release/error'; | ||
import request from 'request'; | ||
import getRepository from './package.js'; | ||
|
||
/** | ||
* Privates | ||
*/ | ||
|
||
const GITHUB_API = 'https://api.github.com'; | ||
|
||
/** | ||
* Interface | ||
*/ | ||
|
||
export default function getHead(pack, version, callback) { | ||
const requestSettings = { | ||
url: `${GITHUB_API}/repos/${getRepository(pack)}/tags`, | ||
json: true, | ||
}; | ||
|
||
request.get(requestSettings, (error, response, tags = []) => { | ||
if (error) return callback(error); | ||
|
||
if (response.statusCode === 200) { | ||
tags.forEach(tag => { | ||
if (tag.name === `v${version}`) { | ||
return callback(null, tag.commit.sha); | ||
} | ||
}); | ||
} | ||
|
||
return callback(new SemanticReleaseError( | ||
`GitHub tag missing on remote: v${version}` | ||
)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Dependencies | ||
*/ | ||
|
||
import url from 'url'; | ||
|
||
/** | ||
* Interface | ||
*/ | ||
|
||
// From https://github.com/atom/apm/blob/master/src%2Fpackages.coffee | ||
export default function getRepository(pack = {}) { | ||
const repository = pack.repository && pack.repository.url || pack.repository; | ||
if (!!repository) { | ||
const repoPath = url.parse(repository.replace(/\.git$/, '')).pathname; | ||
const [name, owner] = repoPath.split('/').slice(-2); | ||
if (name && owner) return `${name}/${owner}`; | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Dependencies | ||
*/ | ||
|
||
import SemanticReleaseError from '@semantic-release/error'; | ||
import request from 'request'; | ||
|
||
/** | ||
* Privates | ||
*/ | ||
|
||
const ATOM_REGISTRY = 'https://atom.io'; | ||
|
||
/** | ||
* Interface | ||
*/ | ||
|
||
export default function atomVersion(pkg, callback) { | ||
const requestSettings = { | ||
url: `${ATOM_REGISTRY}/api/packages/${pkg.name}`, | ||
json: true, | ||
}; | ||
|
||
request.get(requestSettings, (error, response, body = {}) => { | ||
if (error) return callback(error); | ||
|
||
if (response.statusCode === 404) { | ||
return callback(null, null); | ||
} | ||
|
||
const version = body.releases && body.releases.latest; | ||
if (response.statusCode === 200 && !!version) { | ||
return callback(null, version); | ||
} | ||
|
||
const message = body.message || body.error || body; | ||
return callback(new SemanticReleaseError( | ||
`Requesting package failed: ${JSON.stringify(message)}` | ||
)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Dependencies | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import SemanticReleaseError from '@semantic-release/error'; | ||
import nock from 'nock'; | ||
import getHead from '../src/head.js'; | ||
|
||
/** | ||
* Tests | ||
*/ | ||
|
||
const GITHUB_API = 'https://api.github.com'; | ||
const github = nock(GITHUB_API); | ||
|
||
describe('getHead from github', () => { | ||
it('get sha from version', done => { | ||
github.get('/repos/test/test/tags').reply(200, [{ | ||
name: 'v1.1.5', | ||
commit: { sha: 'f9977551c125796199a739f48907eccf71adaca2' }, | ||
}]); | ||
|
||
getHead({ repository: 'https://github.com/test/test.git' }, '1.1.5', (error, sha) => { | ||
expect(error).to.equal(null); | ||
expect(sha).to.equal('f9977551c125796199a739f48907eccf71adaca2'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('missing version', done => { | ||
github.get('/repos/test/test/tags').reply(200, [{ | ||
name: 'hey', | ||
commit: { sha: 'f9977551c125796199a739f48907eccf71adaca2' }, | ||
}]); | ||
|
||
getHead({ repository: 'https://github.com/test/test.git' }, '1.1.5', (error, sha) => { | ||
expect(error).to.exist.and.be.instanceof(SemanticReleaseError); | ||
expect(sha).to.equal(undefined); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('missing package', done => { | ||
github.get('/repos/test/missing/tags').reply(404, { message: 'Not Found' }); | ||
|
||
getHead({ repository: 'https://github.com/test/missing.git' }, '1.0.0', (error, sha) => { | ||
expect(error).to.exist.and.be.instanceof(SemanticReleaseError); | ||
expect(sha).to.equal(undefined); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('request error', done => { | ||
github.get('/repos/test/test/tags').replyWithError('Error'); | ||
|
||
getHead({ repository: 'https://github.com/test/test.git' }, '1.1.5', (error, sha) => { | ||
expect(error).to.exist.and.be.instanceof(Error); | ||
expect(sha).to.equal(undefined); | ||
done(); | ||
}); | ||
}); | ||
}); |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Dependencies | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import getRepository from '../src/package.js'; | ||
|
||
/** | ||
* Tests | ||
*/ | ||
|
||
describe('getRepository from package.json', () => { | ||
it('empty', () => { | ||
expect(getRepository()).to.equal(null); | ||
}); | ||
|
||
it('with object', () => { | ||
expect(getRepository({ | ||
repository: { | ||
type: 'git', | ||
url: 'https://github.com/Adezandee/fast-eslint.git', | ||
}, | ||
})).to.equal('Adezandee/fast-eslint'); | ||
}); | ||
|
||
it('with string', () => { | ||
expect(getRepository({ | ||
repository: 'https://github.com/Adezandee/fast-eslint.git', | ||
})).to.equal('Adezandee/fast-eslint'); | ||
}); | ||
|
||
it('with incomplete', () => { | ||
expect(getRepository({ | ||
repository: 'https://github.com/fast-eslint.git', | ||
})).to.equal(null); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.