Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 127afd9

Browse files
committed
Fix indentations
1 parent 68cf780 commit 127afd9

5 files changed

Lines changed: 175 additions & 175 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ root = true
55

66
[*]
77
indent_style = tab
8-
indent_size = 2
8+
indent_size = 4
99
end_of_line = lf
1010
charset = utf-8
1111
trim_trailing_whitespace = false

lib/check.js

Lines changed: 122 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ const pkg = require('../package.json');
1616
* @param callback {function|undefined} The callback function.
1717
*/
1818
const graphql = (options, callback) => {
19-
// build the query
20-
const theQuery = options.fetchTags ? query.tags(options.repo, options.owner) : query.releases(options.repo, options.owner);
21-
22-
// do the api call
23-
github_graphql({
24-
token: options.token,
25-
query: theQuery
26-
}, (err, res) => {
27-
if (err) {
28-
callback(err, null);
29-
} else {
30-
// Retrieve newer version name
31-
const newer = options.fetchTags ? res.data.repository.refs.nodes[0] : res.data.repository.releases.nodes[0];
32-
33-
// Compare versions
34-
if (semver.gt((options.fetchTags ? newer.name : newer.tag.name), options.currentVersion)) {
35-
callback(null, newer);
36-
} else {
37-
callback(null, null);
38-
}
39-
}
40-
});
19+
// build the query
20+
const theQuery = options.fetchTags ? query.tags(options.repo, options.owner) : query.releases(options.repo, options.owner);
21+
22+
// do the api call
23+
github_graphql({
24+
token: options.token,
25+
query: theQuery
26+
}, (err, res) => {
27+
if (err) {
28+
callback(err, null);
29+
} else {
30+
// Retrieve newer version name
31+
const newer = options.fetchTags ? res.data.repository.refs.nodes[0] : res.data.repository.releases.nodes[0];
32+
33+
// Compare versions
34+
if (semver.gt((options.fetchTags ? newer.name : newer.tag.name), options.currentVersion)) {
35+
callback(null, newer);
36+
} else {
37+
callback(null, null);
38+
}
39+
}
40+
});
4141
};
4242

4343
/**
@@ -50,79 +50,79 @@ const graphql = (options, callback) => {
5050
* @param callback {function|undefined} The callback function.
5151
*/
5252
const rest = (options, callback) => {
53-
const handler = res => {
54-
const chunks = [];
55-
res.on('data', chunk => {
56-
return chunks.push(chunk.toString());
57-
});
58-
res.on('end', () => {
59-
// parse response string into an object
60-
const response = chunks.join('');
61-
let json = null;
62-
try {
63-
json = JSON.parse(response);
64-
} catch (error) {
65-
return callback(error, null);
66-
}
67-
68-
// 404 error occurs, when no releases are found
69-
if (res.statusCode === 404) {
70-
return callback(null, null);
71-
}
72-
73-
// status codes other than 200 are treated as an error
74-
else if (res.statusCode !== 200) {
75-
return callback(new Error(json.message), null);
76-
}
77-
78-
// Compare versions
79-
let found = false;
80-
let version = null;
81-
for (let i = 0; i < json.length; i++) {
82-
version = json[i];
83-
if (semver.gt(version[options.fetchTags ? 'name' : 'tag_name'], options.currentVersion)) {
84-
found = true;
85-
break;
86-
}
87-
}
88-
89-
if (found) {
90-
const mapped = schemeMapper[options.fetchTags ? 'tag' : 'release'](version);
91-
callback(null, mapped);
92-
} else {
93-
callback(null, null);
94-
}
95-
});
96-
};
97-
98-
// build url
99-
let apiUrl = `/repos/${options.owner}/${options.repo}`;
100-
if (options.fetchTags) {
101-
apiUrl += '/tags';
102-
} else {
103-
apiUrl += '/releases';
104-
105-
if (options.latestOnly) {
106-
apiUrl += '/latest';
107-
}
108-
}
109-
110-
// define request options
111-
const opts = {
112-
hostname: 'api.github.com',
113-
path: apiUrl,
114-
headers: {
115-
'Accept': 'application/vnd.github.v3+json',
116-
'User-Agent': `${pkg.name} v${pkg.version}`
117-
}
118-
};
119-
120-
// execute request
121-
let req = https.get(opts, handler);
122-
req.on('error', err => {
123-
callback(err, null);
124-
});
125-
req.end();
53+
const handler = res => {
54+
const chunks = [];
55+
res.on('data', chunk => {
56+
return chunks.push(chunk.toString());
57+
});
58+
res.on('end', () => {
59+
// parse response string into an object
60+
const response = chunks.join('');
61+
let json = null;
62+
try {
63+
json = JSON.parse(response);
64+
} catch (error) {
65+
return callback(error, null);
66+
}
67+
68+
// 404 error occurs, when no releases are found
69+
if (res.statusCode === 404) {
70+
return callback(null, null);
71+
}
72+
73+
// status codes other than 200 are treated as an error
74+
else if (res.statusCode !== 200) {
75+
return callback(new Error(json.message), null);
76+
}
77+
78+
// Compare versions
79+
let found = false;
80+
let version = null;
81+
for (let i = 0; i < json.length; i++) {
82+
version = json[i];
83+
if (semver.gt(version[options.fetchTags ? 'name' : 'tag_name'], options.currentVersion)) {
84+
found = true;
85+
break;
86+
}
87+
}
88+
89+
if (found) {
90+
const mapped = schemeMapper[options.fetchTags ? 'tag' : 'release'](version);
91+
callback(null, mapped);
92+
} else {
93+
callback(null, null);
94+
}
95+
});
96+
};
97+
98+
// build url
99+
let apiUrl = `/repos/${options.owner}/${options.repo}`;
100+
if (options.fetchTags) {
101+
apiUrl += '/tags';
102+
} else {
103+
apiUrl += '/releases';
104+
105+
if (options.latestOnly) {
106+
apiUrl += '/latest';
107+
}
108+
}
109+
110+
// define request options
111+
const opts = {
112+
hostname: 'api.github.com',
113+
path: apiUrl,
114+
headers: {
115+
'Accept': 'application/vnd.github.v3+json',
116+
'User-Agent': `${pkg.name} v${pkg.version}`
117+
}
118+
};
119+
120+
// execute request
121+
let req = https.get(opts, handler);
122+
req.on('error', err => {
123+
callback(err, null);
124+
});
125+
req.end();
126126
};
127127

128128
/**
@@ -138,31 +138,31 @@ module.exports = (options, callback) => {
138138
throw new Error('options object must not be null or undefined!');
139139
}
140140

141-
// get options
142-
options.token = options.token || process.env.GITHUB_API_TOKEN || undefined;
143-
if (options.reduceTraffic) {
144-
console.warn('The "reduceTraffic" option is deprecated! Consider updating "github-version-checker" to a newer version.');
145-
}
146-
147-
// check if required options are defined
148-
if (!options.repo) {
149-
callback('no repository specified', null);
150-
return;
151-
}
152-
if (!options.owner) {
153-
callback('no owner specified', null);
154-
return;
155-
}
156-
if (!options.currentVersion) {
157-
callback('no current version given', null);
158-
return;
159-
}
160-
161-
// decide what to do
162-
// when we have a token supplied, we will call the GraphQL api
163-
if (options.token) {
164-
graphql(options, callback);
165-
} else {
166-
rest(options, callback);
167-
}
141+
// get options
142+
options.token = options.token || process.env.GITHUB_API_TOKEN || undefined;
143+
if (options.reduceTraffic) {
144+
console.warn('The "reduceTraffic" option is deprecated! Consider updating "github-version-checker" to a newer version.');
145+
}
146+
147+
// check if required options are defined
148+
if (!options.repo) {
149+
callback('no repository specified', null);
150+
return;
151+
}
152+
if (!options.owner) {
153+
callback('no owner specified', null);
154+
return;
155+
}
156+
if (!options.currentVersion) {
157+
callback('no current version given', null);
158+
return;
159+
}
160+
161+
// decide what to do
162+
// when we have a token supplied, we will call the GraphQL api
163+
if (options.token) {
164+
graphql(options, callback);
165+
} else {
166+
rest(options, callback);
167+
}
168168
};

lib/main.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ const check = require('./check');
1010
* @return null or a Promise.
1111
*/
1212
module.exports = (options, callback) => {
13-
if (callback) {
14-
check(options, callback);
15-
return null;
16-
} else {
17-
return new Promise((resolve, reject) => {
18-
check(options, (error, update) => {
19-
if (error) reject(error);
20-
else if (update) resolve(update);
21-
else resolve(null);
22-
});
23-
});
24-
}
13+
if (callback) {
14+
check(options, callback);
15+
return null;
16+
} else {
17+
return new Promise((resolve, reject) => {
18+
check(options, (error, update) => {
19+
if (error) reject(error);
20+
else if (update) resolve(update);
21+
else resolve(null);
22+
});
23+
});
24+
}
2525
};

lib/query.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
* @param owner {string} The owner of the repository.
66
*/
77
module.exports.releases = (repo, owner) => {
8-
return `
9-
{
10-
repository(name: "${repo}", owner: "${owner}") {
11-
releases(last: 1) {
12-
nodes {
13-
name
14-
tag {
15-
name
16-
}
17-
isPrerelease
18-
publishedAt
19-
url
20-
}
21-
}
22-
}
23-
}
24-
`;
8+
return `
9+
{
10+
repository(name: "${repo}", owner: "${owner}") {
11+
releases(last: 1) {
12+
nodes {
13+
name
14+
tag {
15+
name
16+
}
17+
isPrerelease
18+
publishedAt
19+
url
20+
}
21+
}
22+
}
23+
}
24+
`;
2525
};
2626

2727
/**
@@ -31,15 +31,15 @@ module.exports.releases = (repo, owner) => {
3131
* @param owner {string} The owner of the repository.
3232
*/
3333
module.exports.tags = (repo, owner) => {
34-
return `
35-
{
36-
repository(name: "${repo}", owner: "${owner}") {
37-
refs(last: 1, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: ASC }) {
38-
nodes {
39-
name
40-
}
41-
}
42-
}
43-
}
44-
`;
34+
return `
35+
{
36+
repository(name: "${repo}", owner: "${owner}") {
37+
refs(last: 1, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: ASC }) {
38+
nodes {
39+
name
40+
}
41+
}
42+
}
43+
}
44+
`;
4545
};

0 commit comments

Comments
 (0)