mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-05-03 23:45:59 +00:00
Enhance issue matching and redirect handling in close_issue_in_dev workflow
This commit is contained in:
+15
-1
@@ -113,7 +113,8 @@ jobs:
|
|||||||
const http = require('http');
|
const http = require('http');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
function request(fullUrl, opts) {
|
function request(fullUrl, opts, redirectsLeft) {
|
||||||
|
if (redirectsLeft === undefined) redirectsLeft = 5;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
const u = url.parse(fullUrl);
|
const u = url.parse(fullUrl);
|
||||||
const isHttps = u.protocol === 'https:';
|
const isHttps = u.protocol === 'https:';
|
||||||
@@ -128,6 +129,19 @@ jobs:
|
|||||||
if (body) options.headers['Content-Length'] = Buffer.byteLength(body);
|
if (body) options.headers['Content-Length'] = Buffer.byteLength(body);
|
||||||
const lib = isHttps ? https : http;
|
const lib = isHttps ? https : http;
|
||||||
const req = lib.request(options, function(res) {
|
const req = lib.request(options, function(res) {
|
||||||
|
// Follow redirects (301/302/307/308)
|
||||||
|
if ([301, 302, 307, 308].indexOf(res.statusCode) !== -1 && res.headers.location && redirectsLeft > 0) {
|
||||||
|
res.resume();
|
||||||
|
const nextUrl = url.resolve(fullUrl, res.headers.location);
|
||||||
|
// For 301/302, browsers historically downgrade to GET; preserve method for 307/308.
|
||||||
|
const nextOpts = Object.assign({}, opts);
|
||||||
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
||||||
|
nextOpts.method = 'GET';
|
||||||
|
delete nextOpts.body;
|
||||||
|
}
|
||||||
|
resolve(request(nextUrl, nextOpts, redirectsLeft - 1));
|
||||||
|
return;
|
||||||
|
}
|
||||||
let data = '';
|
let data = '';
|
||||||
res.on('data', function(chunk) { data += chunk; });
|
res.on('data', function(chunk) { data += chunk; });
|
||||||
res.on('end', function() {
|
res.on('end', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user