Commit cbf3139e authored by Johannes Zellner's avatar Johannes Zellner

Make gitlab api work

parent beac6d0a
......@@ -47,6 +47,7 @@ function getStarred(token, callback) {
}, handleError(callback));
}
// Returns [{ projectId, version, createdAt, sha }]
function getReleases(token, project, callback) {
assert.strictEqual(typeof token, 'string');
assert.strictEqual(typeof project, 'object');
......@@ -56,10 +57,11 @@ function getReleases(token, project, callback) {
var repo = api.getRepo(project.name);
repo.listTags().then(function (result) {
callback(null, result.data);
callback(null, result.data.map(function (r) { return { projectId: project.id, version: r.name, createdAt: r.createdAt, sha: r.commit.sha }; }));
}, handleError(callback));
}
// Returns { createdAt }
function getCommit(token, project, sha, callback) {
assert.strictEqual(typeof token, 'string');
assert.strictEqual(typeof project, 'object');
......@@ -70,6 +72,6 @@ function getCommit(token, project, sha, callback) {
var repo = api.getRepo(project.name);
repo.getCommit(sha).then(function (result) {
callback(null, result.data);
callback(null, { createdAt: result.data.committer.date });
}, callback);
}
......@@ -24,23 +24,29 @@ function getStarred(token, callback) {
callback(new Error('not implemented'));
}
// Returns [{ projectId, version, createdAt, sha }]
function getReleases(token, project, callback) {
assert.strictEqual(typeof token, 'string');
assert.strictEqual(typeof project, 'object');
assert.strictEqual(typeof callback, 'function');
// https://gitlab.example.com/api/v4/projects/24/releases
superagent.get(project.origin + '/api/v4/projects/' + encodeURIComponent(project.name) + '/releases').end(function (error, result) {
if (error) console.error(error);
console.log('---', token, project)
callback(null, []);
callback(null, result.body.map(function (r) { return { projectId: project.id, version: r.name, createdAt: r.created_at, sha: r.commit.id }; }));
});
}
// Returns { createdAt }
function getCommit(token, project, sha, callback) {
assert.strictEqual(typeof token, 'string');
assert.strictEqual(typeof project, 'object');
assert.strictEqual(typeof sha, 'string');
assert.strictEqual(typeof callback, 'function');
callback(new Error('not implemented'));
superagent.get(project.origin + '/api/v4/projects/' + encodeURIComponent(project.name) + '/repository/commits/' + sha).end(function (error, result) {
if (error) console.error(error);
callback(null, { createdAt: result.body.committed_date });
});
}
......@@ -176,6 +176,11 @@ function projectAdd(req, res, next) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(201, { project: result }));
// force an initial release sync
tasks.syncReleasesByProject(req.user, result, function (error) {
if (error) console.error('Failed to perfom initial sync.', error);
});
});
}
......
......@@ -13,7 +13,8 @@ var assert = require('assert'),
github = require('./github.js');
module.exports = exports = {
run: run
run: run,
syncReleasesByProject: syncReleasesByProject // for initial sync on project add
};
const CAN_SEND_EMAIL = (process.env.CLOUDRON_MAIL_SMTP_SERVER && process.env.CLOUDRON_MAIL_SMTP_PORT && process.env.CLOUDRON_MAIL_FROM);
......@@ -142,12 +143,9 @@ function syncReleasesByProject(user, project, callback) {
return callback();
}
api.getReleases(user.githubToken, project, function (error, result) {
api.getReleases(user.githubToken, project, function (error, upstreamReleases) {
if (error) return callback(error);
// map to internal model
var upstreamReleases = result.map(function (r) { return { projectId: project.id, version: r.name, createdAt: r.createdAt, sha: r.commit.sha }; });
database.releases.list(project.id, function (error, trackedReleases) {
if (error) return callback(error);
......@@ -157,12 +155,12 @@ function syncReleasesByProject(user, project, callback) {
// only get the full commit for new releases
async.eachLimit(newReleases, 10, function (release, callback) {
github.getCommit(user.githubToken, project, release.sha, function (error, commit) {
api.getCommit(user.githubToken, project, release.sha, function (error, commit) {
if (error) return callback(error);
// before initial successful sync and if notifications for this project are enabled, we mark the release as not notified yet
release.notified = !project.lastSuccessfulSyncAt ? true : !project.enabled;
release.createdAt = new Date(commit.committer.date).getTime();
release.createdAt = new Date(commit.createdAt).getTime();
delete release.sha;
......
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M16 0C7.16 0 0 7.16 0 16C0 23.08 4.58 29.06 10.94 31.18C11.74 31.32 12.04 30.84 12.04 30.42C12.04 30.04 12.02 28.78 12.02 27.44C8 28.18 6.96 26.46 6.64 25.56C6.46 25.1 5.68 23.68 5 23.3C4.44 23 3.64 22.26 4.98 22.24C6.24 22.22 7.14 23.4 7.44 23.88C8.88 26.3 11.18 25.62 12.1 25.2C12.24 24.16 12.66 23.46 13.12 23.06C9.56 22.66 5.84 21.28 5.84 15.16C5.84 13.42 6.46 11.98 7.48 10.86C7.32 10.46 6.76 8.82 7.64 6.62C7.64 6.62 8.98 6.2 12.04 8.26C13.32 7.9 14.68 7.72 16.04 7.72C17.4 7.72 18.76 7.9 20.04 8.26C23.1 6.18 24.44 6.62 24.44 6.62C25.32 8.82 24.76 10.46 24.6 10.86C25.62 11.98 26.24 13.4 26.24 15.16C26.24 21.3 22.5 22.66 18.94 23.06C19.52 23.56 20.02 24.52 20.02 26.02C20.02 28.16 20 29.88 20 30.42C20 30.84 20.3 31.34 21.1 31.18C27.42 29.06 32 23.06 32 16C32 7.16 24.84 0 16 0V0Z" fill="#24292E"/>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="logo_art"
data-name="logo art"
viewBox="0 0 600 600"
version="1.1"
sodipodi:docname="logo.svg"
inkscape:version="0.92.4 5da689c313, 2019-01-14"
width="600"
height="600"
inkscape:export-filename="/home/nebulon/projects/yellowtent/apps/gitlab-app/logo.png"
inkscape:export-xdpi="81.919998"
inkscape:export-ydpi="81.919998">
<metadata
id="metadata27">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>gitlab-icon-rgb</dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="3200"
inkscape:window-height="1746"
id="namedview25"
showgrid="false"
inkscape:zoom="0.84436494"
inkscape:cx="313.78173"
inkscape:cy="229.52289"
inkscape:window-x="0"
inkscape:window-y="54"
inkscape:window-maximized="1"
inkscape:current-layer="logo_art" />
<defs
id="defs4">
<style
id="style2">.cls-1{fill:#fc6d26;}.cls-2{fill:#e24329;}.cls-3{fill:#fca326;}</style>
</defs>
<title
id="title6">gitlab-icon-rgb</title>
<g
id="g853"
transform="matrix(1.7540259,0,0,1.7540259,-213.92545,-190.25753)">
<g
id="g44">
<path
d="M 461.17,301.83 442.26,243.71 404.84,128.43 a 6.47,6.47 0 0 0 -12.27,0 L 355.15,243.64 H 230.82 L 193.4,128.43 a 6.46,6.46 0 0 0 -12.26,0 l -37.36,115.21 -18.91,58.19 a 12.88,12.88 0 0 0 4.66,14.39 L 293,435 456.44,316.22 a 12.9,12.9 0 0 0 4.73,-14.39"
class="cls-1"
id="path46"
inkscape:connector-curvature="0"
style="fill:#fc6d26" />
</g>
<g
id="g48">
<path
d="m 293,434.91 v 0 L 355.16,243.63 H 230.87 Z"
class="cls-2"
id="path50"
inkscape:connector-curvature="0"
style="fill:#e24329" />
</g>
<g
id="g56">
<path
d="M 293,434.91 230.82,243.63 h -87 z"
class="cls-1"
id="path58"
inkscape:connector-curvature="0"
style="fill:#fc6d26" />
</g>
<g
id="g64">
<path
d="m 143.75,243.69 v 0 l -18.91,58.12 a 12.88,12.88 0 0 0 4.66,14.39 L 293,435 Z"
class="cls-3"
id="path66"
inkscape:connector-curvature="0"
style="fill:#fca326" />
</g>
<g
id="g72">
<path
d="m 143.78,243.69 h 87.11 L 193.4,128.49 a 6.47,6.47 0 0 0 -12.27,0 z"
class="cls-2"
id="path74"
inkscape:connector-curvature="0"
style="fill:#e24329" />
</g>
<g
id="g76">
<path
d="M 293,434.91 355.16,243.63 H 442.3 Z"
class="cls-1"
id="path78"
inkscape:connector-curvature="0"
style="fill:#fc6d26" />
</g>
<g
id="g80">
<path
d="m 442.24,243.69 v 0 l 18.91,58.12 a 12.85,12.85 0 0 1 -4.66,14.39 L 293,434.91 442.2,243.69 Z"
class="cls-3"
id="path82"
inkscape:connector-curvature="0"
style="fill:#fca326" />
</g>
<g
id="g84">
<path
d="m 442.28,243.69 h -87.1 l 37.42,-115.2 a 6.46,6.46 0 0 1 12.26,0 z"
class="cls-2"
id="path86"
inkscape:connector-curvature="0"
style="fill:#e24329" />
</g>
</g>
</svg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment