-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
osslifecycle.service.js
111 lines (102 loc) · 3 KB
/
osslifecycle.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { BaseService, InvalidResponse, pathParams } from '../index.js'
const description = `
OSS Lifecycle is an initiative started by Netflix to classify open-source projects into lifecycles
and clearly identify which projects are active and which ones are retired. To enable this badge,
simply create an OSSMETADATA tagging file at the root of your GitHub repository containing a
single line similar to the following: \`osslifecycle=active\`. Other suggested values are
\`osslifecycle=maintenance\` and \`osslifecycle=archived\`. A working example
can be viewed on the [OSS Tracker repository](https://github.com/Netflix/osstracker).
`
export default class OssTracker extends BaseService {
static category = 'other'
static route = {
base: 'osslifecycle',
pattern: ':user/:repo/:branch*',
}
static openApi = {
'/osslifecycle/{user}/{repo}': {
get: {
summary: 'OSS Lifecycle',
description,
parameters: pathParams(
{
name: 'user',
example: 'Teevity',
},
{
name: 'repo',
example: 'ice',
},
),
},
},
'/osslifecycle/{user}/{repo}/{branch}': {
get: {
summary: 'OSS Lifecycle (branch)',
description,
parameters: pathParams(
{
name: 'user',
example: 'Netflix',
},
{
name: 'repo',
example: 'osstracker',
},
{
name: 'branch',
example: 'documentation',
},
),
},
},
}
static defaultBadgeData = { label: 'oss lifecycle' }
/**
* Return color for active, maintenance and archived statuses, which were the three
* example keywords used in Netflix's open-source meetup.
* See https://slideshare.net/aspyker/netflix-open-source-meetup-season-4-episode-1
* Other keywords are possible, but will appear in grey.
*
* @param {object} attrs Refer to individual attrs
* @param {string} attrs.status Specifies the current maintenance status
* @returns {string} color
*/
static getColor({ status }) {
if (status === 'active') {
return 'brightgreen'
} else if (status === 'maintenance') {
return 'yellow'
} else if (status === 'archived') {
return 'red'
}
return 'lightgrey'
}
static render({ status }) {
const color = this.getColor({ status })
return {
message: status,
color,
}
}
async fetch({ user, repo, branch }) {
return this._request({
url: `https://raw.githubusercontent.com/${user}/${repo}/${branch}/OSSMETADATA`,
})
}
async handle({ user, repo, branch }) {
const { buffer } = await this.fetch({
user,
repo,
branch: branch || 'HEAD',
})
try {
const status = buffer.match(/osslifecycle=([a-z]+)/im)[1]
return this.constructor.render({ status })
} catch (e) {
throw new InvalidResponse({
prettyMessage: 'metadata in unexpected format',
})
}
}
}