forked from webspecs/publican
-
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.
- Loading branch information
Showing
6 changed files
with
55 additions
and
10 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
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 |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
module.exports = [ | ||
require("./git-clone-or-fetch") | ||
, require("./git-publish") | ||
, require("./purge-all") | ||
] | ||
; |
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 |
---|---|---|
@@ -1,16 +1,29 @@ | ||
|
||
var sua = require("superagent"); | ||
var request = require("request"); | ||
|
||
// expects: | ||
// purgeAllURL: the URL to purge Fastly | ||
// purgeAllKey: the key for the Fastly service | ||
module.exports = function (ctx, cb) { | ||
sua.post(ctx.purgeAllURL) | ||
.set("Fastly-Key", ctx.purgeAllKey) | ||
.set('Accept', 'application/json') | ||
.end(function (err, res) { | ||
if (!err && res.body && res.body.status === "ok") return cb(); | ||
cb(new Error(res.body ? res.body.status : "No response body for purge")); | ||
}) | ||
; | ||
|
||
var options = { | ||
url: ctx.purgeAllURL | ||
, method: 'POST' | ||
, headers: { | ||
'User-Agent': 'WebPlatformPublican/1' | ||
, 'Fastly-Key': ctx.purgeAllKey | ||
} | ||
}; | ||
|
||
return request(options, function requestCallback(error, response, body) { | ||
var info = JSON.parse(body); | ||
if (!error && response.statusCode == 200) { | ||
console.log('Purge worked', info); | ||
return cb(); | ||
} else { | ||
cb( new Error('Error purging, message ', info ) ); | ||
} | ||
}); | ||
|
||
}; | ||
|
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,27 @@ | ||
|
||
var request = require("request"); | ||
|
||
module.exports = function (ctx, cb) { | ||
|
||
var parts = ctx.repository.split("/", 2); | ||
var options = { | ||
url: 'https://specs.webplatform.org/' | ||
, method: 'PURGE' | ||
, headers: { | ||
'User-Agent': 'WebPlatformPublican/1' | ||
} | ||
}; | ||
|
||
options.url += parts[1] + '/' + parts[0] + '/' + ctx.branch; | ||
|
||
return request(options, function purgeRequestHandler (error, response, body) { | ||
var info = JSON.parse(body); | ||
if (!error && response.statusCode == 200) { | ||
console.log('Purge worked on ' + options.url, info); | ||
return cb(); | ||
} else { | ||
return cb(new Error('Error purging ' + options.url, info)); | ||
} | ||
}); | ||
|
||
}; |
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