forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-pipenv.service.js
More file actions
180 lines (162 loc) · 4.91 KB
/
Copy pathgithub-pipenv.service.js
File metadata and controls
180 lines (162 loc) · 4.91 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
'use strict'
const { renderVersionBadge } = require('../version')
const { isLockfile, getDependencyVersion } = require('../pipenv-helpers')
const { addv } = require('../text-formatters')
const { NotFound } = require('..')
const { ConditionalGithubAuthV3Service } = require('./github-auth-service')
const { fetchJsonFromRepo } = require('./github-common-fetch')
const { documentation: githubDocumentation } = require('./github-helpers')
const keywords = ['pipfile']
const documentation = `
<p>
<a href="https://github.com/pypa/pipenv">Pipenv</a> is a dependency
manager for Python which manages a
<a href="https://virtualenv.pypa.io/en/latest/">virtualenv</a> for
projects. It adds/removes packages from your <code>Pipfile</code> as
you install/uninstall packages and generates the ever-important
<code>Pipfile.lock</code>, which can be checked in to source control
in order to produce deterministic builds.
</p>
<p>
The GitHub Pipenv badges are intended for applications using Pipenv
which are hosted on GitHub.
</p>
<p>
When <code>Pipfile.lock</code> is checked in, the <strong>GitHub Pipenv
locked dependency version</strong> badge displays the locked version of
a dependency listed in <code>[packages]</code> or
<code>[dev-packages]</code> (or any of their transitive dependencies).
</p>
<p>
Usually a Python version is specified in the <code>Pipfile</code>, which
<code>pipenv lock</code> then places in <code>Pipfile.lock</code>. The
<strong>GitHub Pipenv Python version</strong> badge displays that version.
</p>
${githubDocumentation}
`
class GithubPipenvLockedPythonVersion extends ConditionalGithubAuthV3Service {
static category = 'platform-support'
static route = {
base: 'github/pipenv/locked/python-version',
pattern: ':user/:repo/:branch*',
}
static examples = [
{
title: 'GitHub Pipenv locked Python version',
pattern: ':user/:repo',
namedParams: {
user: 'metabolize',
repo: 'rq-dashboard-on-heroku',
},
staticPreview: this.render({ version: '3.7' }),
documentation,
keywords,
},
{
title: 'GitHub Pipenv locked Python version (branch)',
pattern: ':user/:repo/:branch',
namedParams: {
user: 'metabolize',
repo: 'rq-dashboard-on-heroku',
branch: 'master',
},
staticPreview: this.render({ version: '3.7', branch: 'master' }),
documentation,
keywords,
},
]
static defaultBadgeData = { label: 'python' }
static render({ version, branch }) {
return renderVersionBadge({
version,
tag: branch,
defaultLabel: 'python',
})
}
async handle({ user, repo, branch }) {
const {
_meta: {
requires: { python_version: version },
},
} = await fetchJsonFromRepo(this, {
schema: isLockfile,
user,
repo,
branch,
filename: 'Pipfile.lock',
})
if (version === undefined) {
throw new NotFound({ prettyMessage: 'version not specified' })
}
return this.constructor.render({ version, branch })
}
}
class GithubPipenvLockedDependencyVersion extends ConditionalGithubAuthV3Service {
static category = 'dependencies'
static route = {
base: 'github/pipenv/locked/dependency-version',
pattern: ':user/:repo/:kind(dev)?/:packageName/:branch*',
}
static examples = [
{
title: 'GitHub Pipenv locked dependency version',
pattern: ':user/:repo/:kind(dev)?/:packageName',
namedParams: {
user: 'metabolize',
repo: 'rq-dashboard-on-heroku',
packageName: 'flask',
},
staticPreview: this.render({
dependency: 'flask',
version: '1.1.1',
}),
documentation,
keywords: ['python', ...keywords],
},
{
title: 'GitHub Pipenv locked dependency version (branch)',
pattern: ':user/:repo/:kind(dev)?/:packageName/:branch',
namedParams: {
user: 'metabolize',
repo: 'rq-dashboard-on-heroku',
kind: 'dev',
packageName: 'black',
branch: 'master',
},
staticPreview: this.render({ dependency: 'black', version: '19.3b0' }),
documentation,
keywords: ['python', ...keywords],
},
]
static defaultBadgeData = { label: 'dependency' }
static render({ dependency, version, ref }) {
return {
label: dependency,
message: version ? addv(version) : ref,
color: 'blue',
}
}
async handle({ user, repo, kind, branch, packageName }) {
const lockfileData = await fetchJsonFromRepo(this, {
schema: isLockfile,
user,
repo,
branch,
filename: 'Pipfile.lock',
})
const { version, ref } = getDependencyVersion({
kind,
wantedDependency: packageName,
lockfileData,
})
return this.constructor.render({
dependency: packageName,
version,
ref,
})
}
}
module.exports = [
GithubPipenvLockedPythonVersion,
GithubPipenvLockedDependencyVersion,
]