├── .github
└── workflows
│ └── go-ci.yml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── action
├── flag.go
├── prompt.go
└── update.go
├── config
├── config.go
└── config_test.go
├── go.mod
├── go.sum
├── main.go
├── pkg
├── local.go
├── local_test.go
├── package.go
└── remote.go
├── rfc7464
├── json.go
└── json_test.go
├── status
├── statistics.go
├── statistics_test.go
├── status.go
└── status_test.go
└── upstream
├── debian.go
├── debian_test.go
├── gitea.go
├── gitea_test.go
├── github.go
├── github_atom.go
├── github_atom_test.go
├── github_release.go
├── github_release_test.go
├── github_tags.go
├── github_tags_test.go
├── github_test.go
├── gitlab.go
├── gitlab_test.go
├── npmjs.go
├── npmjs_test.go
├── perl.go
├── perl_test.go
├── python.go
├── python_test.go
├── rubygems.go
├── rubygems_test.go
├── version.go
└── version_test.go
/.github/workflows/go-ci.yml:
--------------------------------------------------------------------------------
1 | name: Go
2 | on: [push, pull_request]
3 | jobs:
4 | build:
5 | name: Build
6 | runs-on: ubuntu-latest
7 | steps:
8 | - name: Set up Go 1.13
9 | uses: actions/setup-go@v1
10 | with:
11 | go-version: 1.13
12 | id: go
13 |
14 | - name: Check out code into the Go module directory
15 | uses: actions/checkout@master
16 |
17 | - name: Get dependencies
18 | run: go mod download
19 |
20 | - name: Test
21 | run: go test $(go list ./...)
22 |
23 | - name: Build
24 | run: go build -v .
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode/
2 | aur-out-of-date
3 | aur-out-of-date_*
4 | debug
5 | vendor/
6 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Release History
2 |
3 | ## 3.2.0 (2021-04-27)
4 |
5 | - Add codeberg.org support, ref [#42](https://github.com/simon04/aur-out-of-date/pull/42) by [@jugendhacker](https://github.com/jugendhacker)
6 |
7 | ## 3.1.0 (2021-03-16)
8 |
9 | - Support `b2sums` ([BLAKE2](https://en.wikipedia.org/wiki/BLAKE_(hash_function)#BLAKE2) checksums), ref [#40](https://github.com/simon04/aur-out-of-date/issues/40)
10 |
11 | ## 3.0.0 (2020-09-06)
12 |
13 | - Run custom check scripts specified as `scripts` in config
14 |
15 | ## 2.4.0 (2020-05-02)
16 |
17 | - `-local` excludes VCS packages unless `-devel` is specified
18 | - Test for version string equality first (e.g., for `pkgver=7.0.0.post3`)
19 | - Alternative GitHub API: set the environment variable `GITHUB_ATOM=1` to use the `…/releases.atom` feed
20 | - Alternative GitHub API: set the environment variable `GITHUB_TAGS=1` to use obtain the version from the most recent Git tag
21 |
22 | ## 2.2.0 (2019-11-03)
23 |
24 | - Require [Go 1.13](https://golang.org/doc/go1.13)
25 | - Optionally update `pkgver`/`pkgrel` in local `PKGBUILD` files (specify `-update` flag)
26 | - Fix handling of unknown result of version comparison
27 |
28 | ## 2.1.0 (2018-10-16)
29 |
30 | - Add Debian support, ref [#29](https://github.com/simon04/aur-out-of-date/pull/29) by [@z3ntu](https://github.com/z3ntu)
31 | - Clean version string: strip `releases/` prefix, ref [#31](https://github.com/simon04/aur-out-of-date/pull/31) by [@z3ntu](https://github.com/z3ntu)
32 | - Handle `-bzr` as VCS packages, ref [#31](https://github.com/simon04/aur-out-of-date/pull/31) by [@z3ntu](https://github.com/z3ntu)
33 |
34 | ## 2.0.0 (2018-09-18)
35 |
36 | - Use Go modules, at least [Go 1.11](https://golang.org/doc/go1.11) is required
37 | - Python: add support for `post*` version suffixes
38 |
39 | ## 1.5.0 (2018-07-05)
40 |
41 | - Add GitLab support, ref [#24](https://github.com/simon04/aur-out-of-date/issues/24) by [@sum01](https://github.com/sum01)
42 | - Python: add support for pypi.org and pypi.io domains
43 | - Python: add support for download URLs containing hashes
44 | - Python: update API URL to pypi.org
45 |
46 | ## 1.4.0 (2018-06-14)
47 |
48 | - Exclude certain versions using config file
49 |
50 | ## 1.3.0 (2018-05-14)
51 |
52 | - GitHub: prefer tag_name over release name
53 | - Clean version string for all providers (strip `v` prefix)
54 |
55 | ## 1.2.0 (2018-05-03)
56 |
57 | - GitHub: support dots in repository names
58 | - Add support for rubygems.org
59 |
60 | ## 1.1.0 (2018-03-29)
61 |
62 | - NPM: support `@scoped/packages`
63 | - GitHub: fall back to `tag_name` when release does not have a `name`
64 |
65 | ## 1.0.0 (2018-03-06)
66 |
67 | - Use [GitHub releases API](https://developer.github.com/v3/repos/releases/) to skip pre-releases, release drafts
68 | - Cache HTTP requests using `github.com/gregjones/httpcache`
69 | - Provide machine-readable format: JSON Text Sequences ([RFC 7464](https://tools.ietf.org/html/rfc7464))
70 | - Exit with code `4` if at least one out-of-date package has been found
71 | - Fix error on Unicode characters in package version
72 |
73 | ## 0.8.0 (2018-02-24)
74 |
75 | - Print summary statistics
76 | - Flag AUR package out-of-date
77 | - Fix checking huge number of packages
78 |
79 | ## 0.7.0 (2018-02-06)
80 |
81 | - Read local .SRCINFO files
82 | - Handle split packages correctly
83 |
84 | ## 0.6.0 (2018-01-27)
85 |
86 | - Add flag to handle VCS packages only or skip them
87 | - Add support for cpan.org
88 |
89 | ## 0.5.0 (2018-01-21)
90 |
91 | - Add support for registry.npmjs.org
92 | - Add support for pypi.python.org
93 |
94 | ## 0.4.0 (2018-01-21)
95 |
96 | - Initial release including support for GitHub releases
97 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # aur-out-of-date
2 |
3 | Iterates through a user's AUR (Arch User Repository) packages, and determines out-of-date packages w.r.t. their upstream version.
4 |
5 | ⚠️ [Leaving Arch Linux](https://lists.archlinux.org/pipermail/aur-general/2021-November/036683.html) in November 2021 – I'll keep maintaining the project, but don't expect new features unless _you_ are submitting a patch.
6 |
7 | ## Installation
8 |
9 | ```sh
10 | $ go get github.com/simon04/aur-out-of-date
11 | ```
12 |
13 | Since modern Go features (such as modules) are used, at least [Go 1.13](https://golang.org/doc/go1.13) is required.
14 |
15 | The tool is also available in AUR: [aur-out-of-date](https://aur.archlinux.org/packages/aur-out-of-date/)
16 |
17 | ## Usage
18 |
19 | ```
20 | $ aur-out-of-date
21 | Usage of aur-out-of-date:
22 | -config string
23 | Config file (default "$XDG_CONFIG_HOME/aur-out-of-date/config.json")
24 | -devel
25 | Check -git/-svn/-hg packages
26 | -flag
27 | Flag out-of-date on AUR
28 | -json
29 | Generate JSON Text Sequences (RFC 7464)
30 | -local
31 | Local .SRCINFO files
32 | -pkg
33 | AUR package name(s)
34 | -statistics
35 | Print summary statistics
36 | -update
37 | Update pkgver/pkgrel in local PKGBUILD files
38 | -user string
39 | AUR username
40 | ```
41 |
42 | AUR packages can be obtained …
43 |
44 | - for a given AUR user (using `-user simon04`; specify `-devel` to include VCS packages), or
45 | - from a list of packages via [AUR RPC](https://aur.archlinux.org/rpc.php) (using `-pkg package1 package2 …`), or
46 | - from local `.SRCINFO` files (using `-local packages/*/.SRCINFO`).
47 |
48 | ```
49 | $ aur-out-of-date -user simon04
50 | [OUT-OF-DATE] [python-mwclient] Package python-mwclient should be updated from 0.8.6-1 to 0.8.7-1
51 | [OUT-OF-DATE] [nodejs-osmtogeojson] Package nodejs-osmtogeojson should be updated from 2.2.12-1 to 3.0.0
52 | [OUT-OF-DATE] [spectre-meltdown-checker] Package spectre-meltdown-checker should be updated from 0.31-1 to 0.32
53 |
54 | $ aur-out-of-date -user simon04 -devel
55 | [UP-TO-DATE] [ocproxy-git] Package ocproxy-git 1.60.r8.g8f15425-3 matches upstream version 1.60
56 |
57 | $ aur-out-of-date -pkg caddy dep aur-out-of-date
58 | [UP-TO-DATE] [aur-out-of-date] Package aur-out-of-date 0.4.0-1 matches upstream version 0.4.0
59 | [UP-TO-DATE] [caddy] Package caddy 0.10.10-3 matches upstream version 0.10.10
60 | [UP-TO-DATE] [dep] Package dep 0.3.2-2 matches upstream version 0.3.2
61 |
62 | $ aur-out-of-date -local packages/*/.SRCINFO
63 | ```
64 |
65 | The output can be switched to a machine-readable format – [JavaScript Object Notation (JSON) Text Sequences](https://tools.ietf.org/html/rfc7464) – using `-json`.
66 |
67 | ```json
68 | $ aur-out-of-date -json -pkg nodejs-osmtogeojson spectre-meltdown-checker
69 | {"type":"package","name":"nodejs-osmtogeojson","message":"Package nodejs-osmtogeojson should be updated from 2.2.12-1 to 3.0.0","version":"2.2.12-1","upstream":"3.0.0","status":"OUT-OF-DATE"}
70 | {"type":"package","name":"spectre-meltdown-checker","message":"Package spectre-meltdown-checker 0.35-1 matches upstream version 0.35","version":"0.35-1","upstream":"0.35","status":"UP-TO-DATE"}
71 | ```
72 |
73 | Summary statistics can be enabled using `-statistics`.
74 |
75 | The option `-flag` flags out-of-date packages on AUR after a user prompt: "Should the package … be flagged out-of-date?"
76 |
77 | The tool `aur-out-of-date` exists with code `4` if at least one out-of-date package has been found.
78 |
79 | ## Principle
80 |
81 | For each package, the upstream URL and/or source URL is matched against supported platforms. For those platforms the latest release is obtained via an API/HTTP call.
82 |
83 | - `github.com` or `github.io`
84 | - - → https://github.com/…/…/releases.atom if the environment variable `GITHUB_ATOM` is nonempty.
85 | - - → http://api.github.com/repos/…/…/releases/latest (provide a [personal access token](https://github.com/settings/tokens) in the environment variable `GITHUB_TOKEN` for [higher request limits](https://developer.github.com/v3/#rate-limiting); [no scope](https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/) needs to be selected when creating the token)
86 | - - → http://api.github.com/repos/…/…/tags if the environment variable `GITHUB_TAGS` is nonempty (request limits applies).
87 | - `registry.npmjs.org` → https://registry.npmjs.org/-/package/…/dist-tags
88 | - `pypi.org` or `pypi.io` or `pypi.python.org` or `files.pythonhosted.org` → https://pypi.python.org/pypi/…/json
89 | - `search.cpan.org` or `search.mcpan.org` → https://fastapi.metacpan.org/v1/release/…
90 | - `rubygems.org` or `gems.rubyforge.org` → https://rubygems.org/api/v1/versions/….json
91 | - `gitlab.com` or any self-hosted GitLab instance → http://gitlab.com/api/v4/…/…/repository/tags (provide a [personal access token](https://github.com/settings/tokens) in the environment variable `GITLAB_TOKEN` for [higher request limits](https://docs.gitlab.com/ee/api/#oauth2-tokens))
92 |
93 | ## Configuration
94 |
95 | The tool reads a configuration file from `$XDG_CONFIG_HOME/aur-out-of-date/config.json`.
96 |
97 | ```json
98 | {
99 | "ignore": {
100 | "foo": ["*"],
101 | "osmtogeojson": ["3.0.0-beta.3", "3.0.0-rc.1"]
102 | },
103 | "scripts": {
104 | "bar": "echo 42",
105 | "aurweb": "curl -s https://aur.archlinux.org/ | grep aurweb.git/log | grep -oE 'v[1-9][.0-9]+' | head -n1"
106 | }
107 | }
108 | ```
109 |
110 | ### Ignoring versions
111 |
112 | The `ignore` key configuration file allows to ignore certain package versions from being reported as out-of-date. The string `"*"` acts as a placeholder for all versions.
113 |
114 | Running `aur-out-of-date -pkg osmtogeojson` yields:
115 |
116 | ```
117 | [UNKNOWN] [osmtogeojson][3.0.0b3-2] ignoring package upgrade to 3.0.0-beta.3
118 | ```
119 |
120 | ### Using custom version script
121 |
122 | You may specify a custom version script via `scripts`. The given script is executed as `/bin/sh -c $SCRIPT`, and its output is used as upstream version.
123 |
124 | ```
125 | [UP-TO-DATE] [bar] Package bar 42-1 matches upstream version 42
126 | ```
127 |
128 | ## Related projects
129 |
130 | - https://github.com/repology/repology
131 | - https://github.com/lilydjwg/nvchecker
132 |
133 | ## License
134 |
135 | GNU General Public License v3.0
136 |
--------------------------------------------------------------------------------
/action/flag.go:
--------------------------------------------------------------------------------
1 | package action
2 |
3 | import (
4 | "fmt"
5 | "os/exec"
6 | "strings"
7 |
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | "github.com/simon04/aur-out-of-date/upstream"
10 | )
11 |
12 | // FlagOnAur flags the package out-of-date after prompting the user
13 | func FlagOnAur(pkg pkg.Pkg, upstreamVersion upstream.Version) {
14 | fmt.Printf("Should the package %s be flagged out-of-date? [y/N] ", pkg.Name())
15 | if !promptYesNo() {
16 | return
17 | }
18 | fmt.Printf("Flagging package %s out-of-date ...\n", pkg.Name())
19 | comment := fmt.Sprintf("Version %s is out. #simon04/aur-out-of-date", upstreamVersion)
20 | cmd := exec.Command("ssh", "aur@aur.archlinux.org", "flag", pkg.Name(), "\""+comment+"\"")
21 | output, err := cmd.CombinedOutput()
22 | if err != nil {
23 | fmt.Printf("Failed to flag out-of-date (running \"%v\"): %v\n%s\n", strings.Join(cmd.Args, "\" \""), err, output)
24 | } else {
25 | fmt.Printf("%s", output)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/action/prompt.go:
--------------------------------------------------------------------------------
1 | package action
2 |
3 | import "fmt"
4 |
5 | func promptYesNo() bool {
6 | var response string
7 | chars, err := fmt.Scanln(&response)
8 | if err != nil || chars == 0 {
9 | return false
10 | }
11 | if response != "y" && response != "Y" {
12 | return false
13 | }
14 | return true
15 | }
16 |
--------------------------------------------------------------------------------
/action/update.go:
--------------------------------------------------------------------------------
1 | package action
2 |
3 | import (
4 | "fmt"
5 | "io/ioutil"
6 | "strings"
7 |
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | "github.com/simon04/aur-out-of-date/upstream"
10 | )
11 |
12 | // UpdatePKGBUILD updates pkgver/pkgrel in local PKGBUILD files after prompting the user
13 | func UpdatePKGBUILD(pkg pkg.Pkg, upstreamVersion upstream.Version) {
14 | file := pkg.LocalPKGBUILD()
15 | if file == "" {
16 | return
17 | }
18 | input, err := ioutil.ReadFile(file)
19 | if err != nil {
20 | fmt.Printf("updatePKGBUILD: failed to read file %s: %v\n", file, err)
21 | }
22 |
23 | lines := strings.Split(string(input), "\n")
24 |
25 | for i, line := range lines {
26 | if strings.HasPrefix(line, "pkgver=") {
27 | lineUpdate := strings.Replace(line, string(pkg.Version().Version), upstreamVersion.String(), 1)
28 | fmt.Printf("--- a/%s\n", file)
29 | fmt.Printf("+++ b/%s\n", file)
30 | fmt.Printf("-%s\n", line)
31 | fmt.Printf("+%s\n", lineUpdate)
32 | fmt.Printf("Should the package %s be updated to version %s? [y/N] ", pkg.Name(), upstreamVersion)
33 | if !promptYesNo() {
34 | return
35 | }
36 | lines[i] = lineUpdate
37 | } else if strings.HasPrefix(line, "pkgrel=") {
38 | lines[i] = "pkgrel=1"
39 | }
40 | }
41 | err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0644)
42 | if err != nil {
43 | fmt.Printf("updatePKGBUILD: failed to write file %s: %v\n", file, err)
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/config/config.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "encoding/json"
5 | "os"
6 |
7 | "github.com/simon04/aur-out-of-date/upstream"
8 | )
9 |
10 | // Config contains options for running aur-out-of-date
11 | type Config struct {
12 | Ignore map[string]([]upstream.Version) `json:"ignore"`
13 | Scripts map[string]string `json:"scripts"`
14 | }
15 |
16 | // FromFile reads the config from the given filename
17 | func FromFile(filename string) (*Config, error) {
18 | var config Config
19 | if _, err := os.Stat(filename); os.IsNotExist(err) {
20 | return &config, nil
21 | }
22 | f, err := os.Open(filename)
23 | if err != nil {
24 | return nil, err
25 | }
26 | dec := json.NewDecoder(f)
27 | err = dec.Decode(&config)
28 | if err != nil {
29 | return nil, err
30 | }
31 | return &config, nil
32 | }
33 |
34 | // IsIgnored determines whether the package in version is to be ignored
35 | func (conf *Config) IsIgnored(pkg string, version upstream.Version) bool {
36 | ignoredVersions, ok := conf.Ignore[pkg]
37 | if !ok {
38 | return false
39 | }
40 | for _, v := range ignoredVersions {
41 | if v == "*" || v.String() == version.String() {
42 | return true
43 | }
44 | }
45 | return false
46 | }
47 |
--------------------------------------------------------------------------------
/config/config_test.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/simon04/aur-out-of-date/upstream"
7 | )
8 |
9 | func TestIsIgnored(t *testing.T) {
10 | conf := Config{
11 | Ignore: map[string][]upstream.Version{
12 | "foo": {"*"},
13 | "bar": {"0.1", "0.2-alpha.1", "0.2-beta.1"},
14 | "baz": {},
15 | },
16 | }
17 | if !conf.IsIgnored("foo", "1.0") {
18 | t.Errorf("foo-1.0 should be ignored")
19 | }
20 | if !conf.IsIgnored("foo", "2.0") {
21 | t.Errorf("foo-2.0 should be ignored")
22 | }
23 | if !conf.IsIgnored("foo", "*") {
24 | t.Errorf("foo-* should be ignored")
25 | }
26 | if !conf.IsIgnored("bar", "0.2-beta.1") {
27 | t.Errorf("bar-0.2-beta.1 should be ignored")
28 | }
29 | if conf.IsIgnored("bar", "*") {
30 | t.Errorf("bar-* should not be ignored")
31 | }
32 | if conf.IsIgnored("baz", "1.0") {
33 | t.Errorf("baz-1.0 should not be ignored")
34 | }
35 | if conf.IsIgnored("baz-bin", "1.0") {
36 | t.Errorf("baz-bin-1.0 should not be ignored")
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/simon04/aur-out-of-date
2 |
3 | require (
4 | github.com/google/btree v1.0.0 // indirect
5 | github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
6 | github.com/h2non/gock v1.0.7
7 | github.com/mikkeloscar/aur v0.0.0-20190912174111-183f80a38525
8 | github.com/mikkeloscar/gopkgbuild v0.0.0-20201010175455-2582c34596c6
9 | github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 // indirect
10 | github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
11 | )
12 |
13 | go 1.13
14 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
2 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
3 | github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
4 | github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
5 | github.com/h2non/gock v1.0.7 h1:ysCe8XR0rX0kZJJgJgkXN9oz9/Ja5tFA1s+mClGBE0M=
6 | github.com/h2non/gock v1.0.7/go.mod h1:CZMcB0Lg5IWnr9bF79pPMg9WeV6WumxQiUJ1UvdO1iE=
7 | github.com/mikkeloscar/aur v0.0.0-20190912174111-183f80a38525 h1:T0cWcTw55+0h3bEBHWkDPEKYutNIksrDU4aJfkBJTpo=
8 | github.com/mikkeloscar/aur v0.0.0-20190912174111-183f80a38525/go.mod h1:nYOKcK8tIj69ZZ8uDOWoiT+L25NvlOQaraDqTec/idA=
9 | github.com/mikkeloscar/gopkgbuild v0.0.0-20201010175455-2582c34596c6 h1:uHn04ei/KII4V7ly0E2sF9ofnnOb+u8zQs6e4aZw198=
10 | github.com/mikkeloscar/gopkgbuild v0.0.0-20201010175455-2582c34596c6/go.mod h1:OtVZW5UuwGtEXKKNzzViOdA8YG1El15Hs3I3PU++hoY=
11 | github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
12 | github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
13 | github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
14 | github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
15 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "flag"
5 | "fmt"
6 | "net/http"
7 | "os"
8 | "path"
9 | "sort"
10 | "strings"
11 |
12 | "github.com/gregjones/httpcache"
13 | "github.com/gregjones/httpcache/diskcache"
14 | "github.com/mikkeloscar/aur"
15 | "github.com/simon04/aur-out-of-date/action"
16 | "github.com/simon04/aur-out-of-date/config"
17 | "github.com/simon04/aur-out-of-date/pkg"
18 | "github.com/simon04/aur-out-of-date/status"
19 | "github.com/simon04/aur-out-of-date/upstream"
20 | )
21 |
22 | var conf *config.Config
23 | var statistics status.Statistics
24 |
25 | var commandline struct {
26 | user string
27 | config string
28 | remote bool
29 | local bool
30 | includeVcsPkgs bool
31 | printJSON bool
32 | printStatistics bool
33 | flagOnAur bool
34 | updatePKGBUILD bool
35 | }
36 |
37 | func version(pkg pkg.Pkg) (upstream.Version, error) {
38 | if script, ok := conf.Scripts[pkg.Name()]; ok {
39 | return upstream.VersionForScript(script)
40 | }
41 | return upstream.VersionForPkg(pkg)
42 | }
43 |
44 | func handlePackage(pkg pkg.Pkg) status.Status {
45 |
46 | pkgVersion := pkg.Version()
47 | s := status.Status{
48 | Package: pkg.Name(),
49 | FlaggedOutOfDate: pkg.OutOfDate(),
50 | Version: pkgVersion.String(),
51 | }
52 |
53 | upstreamVersion, err := version(pkg)
54 | if err != nil {
55 | s.Status = status.Unknown
56 | s.Message = err.Error()
57 | statistics.Unknown++
58 | return s
59 | }
60 |
61 | s.Ignored = conf.IsIgnored(pkg.Name(), upstreamVersion)
62 | s.Compare(upstreamVersion)
63 | statistics.Update(s.Status)
64 | return s
65 | }
66 |
67 | func handlePackages(vcsPackages bool, packages []pkg.Pkg, err error) {
68 | if err != nil {
69 | panic(err)
70 | }
71 | sort.Slice(packages, func(i, j int) bool { return strings.Compare(packages[i].Name(), packages[j].Name()) == -1 })
72 | for _, pkg := range packages {
73 | if vcsPackages == pkg.IsVcs() {
74 | s := handlePackage(pkg)
75 | if commandline.printJSON {
76 | s.PrintJSONTextSequence()
77 | } else {
78 | s.Print()
79 | }
80 | if s.Status == status.OutOfDate && commandline.flagOnAur {
81 | action.FlagOnAur(pkg, s.Upstream)
82 | }
83 | if s.Status == status.OutOfDate && commandline.updatePKGBUILD {
84 | action.UpdatePKGBUILD(pkg, s.Upstream)
85 | }
86 | }
87 | }
88 | }
89 |
90 | func main() {
91 | configDir, _ := os.UserConfigDir()
92 | defaultConfigFile := path.Join(configDir, "aur-out-of-date", "config.json")
93 | flag.StringVar(&commandline.user, "user", "", "AUR username")
94 | flag.StringVar(&commandline.config, "config", defaultConfigFile, "Config file")
95 | flag.BoolVar(&commandline.remote, "pkg", false, "AUR package name(s)")
96 | flag.BoolVar(&commandline.local, "local", false, "Local .SRCINFO files")
97 | flag.BoolVar(&commandline.includeVcsPkgs, "devel", false, "Check -git/-svn/-hg packages")
98 | flag.BoolVar(&commandline.printStatistics, "statistics", false, "Print summary statistics")
99 | flag.BoolVar(&commandline.flagOnAur, "flag", false, "Flag out-of-date on AUR")
100 | flag.BoolVar(&commandline.updatePKGBUILD, "update", false, "Update pkgver/pkgrel in local PKGBUILD files")
101 | flag.BoolVar(&commandline.printJSON, "json", false, "Generate JSON Text Sequences (RFC 7464)")
102 | flag.Parse()
103 |
104 | // cache HTTP requests (RFC 7234)
105 | cacheDir, _ := os.UserCacheDir()
106 | cacheDir = path.Join(cacheDir, "aur-out-of-date")
107 | http.DefaultClient = httpcache.NewTransport(diskcache.New(cacheDir)).Client()
108 |
109 | if c, err := config.FromFile(commandline.config); err != nil {
110 | fmt.Fprintln(os.Stderr, "Failed to read config:", err)
111 | os.Exit(1)
112 | } else {
113 | conf = c
114 | }
115 |
116 | if commandline.user != "" {
117 | packages, err := aur.SearchBy(commandline.user, aur.Maintainer)
118 | handlePackages(commandline.includeVcsPkgs, pkg.NewRemotePkgs(packages), err)
119 | } else if commandline.remote {
120 | pkgs := flag.Args()
121 | for len(pkgs) > 0 {
122 | limit := 100
123 | if len(pkgs) < limit {
124 | limit = len(pkgs)
125 | }
126 | packages, err := aur.Info(pkgs[:limit])
127 | handlePackages(false, pkg.NewRemotePkgs(packages), err)
128 | handlePackages(true, pkg.NewRemotePkgs(packages), err)
129 | pkgs = pkgs[limit:]
130 | }
131 | } else if commandline.local {
132 | packages, err := pkg.NewLocalPkgs(flag.Args(), commandline.includeVcsPkgs)
133 | handlePackages(false, packages, err)
134 | handlePackages(true, packages, err)
135 | } else {
136 | fmt.Fprintln(os.Stderr, "Either -user or -pkg or -local is required!")
137 | flag.Usage()
138 | os.Exit(1)
139 | }
140 | if commandline.printStatistics && commandline.printJSON {
141 | statistics.PrintJSONTextSequence()
142 | } else if commandline.printStatistics {
143 | statistics.Print()
144 | }
145 | if statistics.OutOfDate > 0 {
146 | os.Exit(4)
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/pkg/local.go:
--------------------------------------------------------------------------------
1 | package pkg
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 |
7 | pkgbuild "github.com/mikkeloscar/gopkgbuild"
8 | )
9 |
10 | // NewLocalPkgs creates a Pkg slice from paths to .SRCINFO files.
11 | func NewLocalPkgs(paths []string, includeVcsPkgs bool) ([]Pkg, error) {
12 | var r []Pkg
13 | for _, path := range paths {
14 | pkg, err := pkgbuild.ParseSRCINFO(path)
15 | if err != nil {
16 | return nil, fmt.Errorf("Failed to parse %s: %w", path, err)
17 | }
18 | if pkg.IsDevel() && !includeVcsPkgs {
19 | continue
20 | }
21 | r = append(r, &localPkg{pkg, path})
22 | }
23 | return r, nil
24 | }
25 |
26 | type localPkg struct {
27 | pkg *pkgbuild.PKGBUILD
28 | path string
29 | }
30 |
31 | func (p *localPkg) Name() string {
32 | return p.pkg.Pkgnames[0]
33 | }
34 |
35 | func (p *localPkg) Version() *pkgbuild.CompleteVersion {
36 | return &pkgbuild.CompleteVersion{
37 | Epoch: uint8(p.pkg.Epoch),
38 | Version: p.pkg.Pkgver,
39 | Pkgrel: p.pkg.Pkgrel,
40 | }
41 | }
42 |
43 | func (p *localPkg) IsVcs() bool {
44 | return p.pkg.IsDevel()
45 | }
46 |
47 | func (p *localPkg) LocalPKGBUILD() string {
48 | return strings.Replace(p.path, ".SRCINFO", "PKGBUILD", 1)
49 | }
50 |
51 | func (p *localPkg) URL() string {
52 | return p.pkg.URL
53 | }
54 |
55 | func (p *localPkg) Sources() ([]string, error) {
56 | return p.pkg.Source, nil
57 | }
58 |
59 | func (p *localPkg) OutOfDate() bool {
60 | return false
61 | }
62 |
--------------------------------------------------------------------------------
/pkg/local_test.go:
--------------------------------------------------------------------------------
1 | package pkg
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 |
7 | "github.com/h2non/gock"
8 | "github.com/mikkeloscar/aur"
9 | )
10 |
11 | func mockInfo() *gock.Response {
12 | g := gock.New("https://aur.archlinux.org/")
13 | g.URLStruct.RawPath = "/rpc.php?arg[]=python2-mwclient&type=info&v=5"
14 | return g.
15 | Reply(http.StatusOK).
16 | SetHeader("Content-Type", "application/json").
17 | BodyString(`
18 | {
19 | "version": 5,
20 | "type": "multiinfo",
21 | "resultcount": 1,
22 | "results": [
23 | {
24 | "ID": 533001,
25 | "Name": "python2-mwclient",
26 | "PackageBaseID": 109452,
27 | "PackageBase": "python-mwclient",
28 | "Version": "0.9.1-1",
29 | "Description": "A Python framework to interface with the MediaWiki API",
30 | "URL": "https://github.com/mwclient/mwclient",
31 | "NumVotes": 6,
32 | "Popularity": 0.455733,
33 | "OutOfDate": null,
34 | "Maintainer": "simon04",
35 | "FirstSubmitted": 1459241039,
36 | "LastModified": 1533710052,
37 | "URLPath": "/cgit/aur.git/snapshot/python-mwclient.tar.gz",
38 | "Depends": ["python2", "python2-requests-oauthlib"],
39 | "License": ["MIT"],
40 | "Keywords": []
41 | }
42 | ]
43 | }`)
44 | }
45 |
46 | func mockSRCINFO() *gock.Response {
47 | g := gock.New("https://aur.archlinux.org/")
48 | g.URLStruct.RawPath = "/cgit/aur.git/plain/.SRCINFO?h=python-mwclient"
49 | return g.
50 | Reply(http.StatusOK).
51 | BodyString("pkgbase = python-mwclient\n\tpkgdesc = A Python framework to interface with the MediaWiki API\n\tpkgver = 0.9.1\n\tpkgrel = 1\n\turl = https://github.com/mwclient/mwclient\n\tarch = any\n\tlicense = MIT\n\tsource = python-mwclient-0.9.1.tar.gz::https://github.com/mwclient/mwclient/archive/v0.9.1.tar.gz\n\tsha512sums = e2c8d720bc583f2cf0de2bdfaab3dfce9f23ed541c34fa8d164d35e9c134e39110d1f9b791daf4a4cf79f18084052ec644ba96980d2037a06b2d0a7851af5ed4\n\npkgname = python-mwclient\n\tdepends = python\n\tdepends = python-requests-oauthlib\n\npkgname = python2-mwclient\n\tdepends = python2\n\tdepends = python2-requests-oauthlib\n")
52 | }
53 |
54 | func TestSplitPkg(t *testing.T) {
55 | defer gock.Off()
56 | mockInfo()
57 | mockSRCINFO()
58 |
59 | info, err := aur.Info([]string{"python2-mwclient"})
60 | if err != nil {
61 | t.Error(err)
62 | }
63 | pkgs := NewRemotePkgs(info)
64 | if len(pkgs) != 1 {
65 | t.Errorf("Found %d pkgs!", len(pkgs))
66 | }
67 | sources, err := pkgs[0].Sources()
68 | if err != nil {
69 | t.Error(err)
70 | }
71 | if len(sources) == 0 || sources[0] != "python-mwclient-0.9.1.tar.gz::https://github.com/mwclient/mwclient/archive/v0.9.1.tar.gz" {
72 | t.Errorf("Unexpected sources %v", sources)
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/pkg/package.go:
--------------------------------------------------------------------------------
1 | package pkg
2 |
3 | import (
4 | pkgbuild "github.com/mikkeloscar/gopkgbuild"
5 | )
6 |
7 | // Pkg is an interface representing an Arch Linux package.
8 | type Pkg interface {
9 | Name() string
10 | Version() *pkgbuild.CompleteVersion
11 | // IsVcs checks whether pkg ends in -bzr or -git or -svn
12 | IsVcs() bool
13 | LocalPKGBUILD() string
14 | URL() string
15 | Sources() ([]string, error)
16 | OutOfDate() bool
17 | }
18 |
19 | // New creates a Pkg from the given parameters. Mainly used for testing.
20 | func New(name, version, url string, sources ...string) Pkg {
21 | pkg := pkgbuild.PKGBUILD{
22 | Pkgbase: name,
23 | Pkgnames: []string{name},
24 | Pkgver: pkgbuild.Version(version),
25 | Pkgrel: "1",
26 | URL: url,
27 | Source: sources,
28 | }
29 | return &localPkg{pkg: &pkg, path: ""}
30 | }
31 |
--------------------------------------------------------------------------------
/pkg/remote.go:
--------------------------------------------------------------------------------
1 | package pkg
2 |
3 | import (
4 | "fmt"
5 | "io/ioutil"
6 | "net/http"
7 |
8 | "github.com/mikkeloscar/aur"
9 | pkgbuild "github.com/mikkeloscar/gopkgbuild"
10 | )
11 |
12 | // NewRemotePkgs creates a Pkg slice from information returned from AUR RPC.
13 | func NewRemotePkgs(pkg []aur.Pkg) []Pkg {
14 | var r []Pkg
15 | for i := range pkg {
16 | r = append(r, &remotePkg{&pkg[i]})
17 | }
18 | return r
19 | }
20 |
21 | type remotePkg struct {
22 | pkg *aur.Pkg
23 | }
24 |
25 | func (p *remotePkg) Name() string {
26 | return p.pkg.Name
27 | }
28 |
29 | func (p *remotePkg) Version() *pkgbuild.CompleteVersion {
30 | version, _ := pkgbuild.NewCompleteVersion(p.pkg.Version)
31 | return version
32 | }
33 |
34 | func (p *remotePkg) IsVcs() bool {
35 | pkgbuild := pkgbuild.PKGBUILD{
36 | Pkgnames: []string{p.Name()},
37 | }
38 | return pkgbuild.IsDevel()
39 | }
40 |
41 | func (p *remotePkg) LocalPKGBUILD() string {
42 | return ""
43 | }
44 |
45 | func (p *remotePkg) URL() string {
46 | return p.pkg.URL
47 | }
48 |
49 | func (p *remotePkg) Sources() ([]string, error) {
50 | resp, err := http.Get("https://aur.archlinux.org/cgit/aur.git/plain/.SRCINFO?h=" + p.pkg.PackageBase)
51 | if err != nil {
52 | return nil, fmt.Errorf("Failed to fetch .SRCINFO for %s: %w", p.pkg.Name, err)
53 | }
54 | defer resp.Body.Close()
55 | pkgbuildBytes, err := ioutil.ReadAll(resp.Body)
56 | if err != nil {
57 | return nil, fmt.Errorf("Failed to fetch .SRCINFO for %s: %w", p.pkg.Name, err)
58 | }
59 | pkg, err := pkgbuild.ParseSRCINFOContent(pkgbuildBytes)
60 | if err != nil {
61 | return nil, fmt.Errorf("Failed to parse .SRCINFO for %s: %w", p.pkg.Name, err)
62 | }
63 | return pkg.Source, nil
64 | }
65 |
66 | func (p *remotePkg) OutOfDate() bool {
67 | return p.pkg.OutOfDate > 0
68 | }
69 |
--------------------------------------------------------------------------------
/rfc7464/json.go:
--------------------------------------------------------------------------------
1 | package rfc7464
2 |
3 | import (
4 | "encoding/json"
5 | "io"
6 | )
7 |
8 | // An Encoder writes JSON Text Sequences to an output stream.
9 | type Encoder struct {
10 | w io.Writer
11 | }
12 |
13 | // NewEncoder returns a new encoder that writes to w.
14 | func NewEncoder(w io.Writer) *Encoder {
15 | return &Encoder{w}
16 | }
17 |
18 | // Encode writes v as JSON Text Sequence (RFC 7464) to the stream.
19 | func (enc *Encoder) Encode(v interface{}) error {
20 | // https://tools.ietf.org/html/rfc7464 JavaScript Object Notation (JSON) Text Sequences
21 | bytes, err := json.Marshal(v)
22 | if err != nil {
23 | return err
24 | }
25 | // record separator
26 | if _, err = enc.w.Write([]byte("\u001e")); err != nil {
27 | return err
28 | }
29 | if _, err = enc.w.Write(bytes); err != nil {
30 | return err
31 | }
32 | // line feed
33 | if _, err = enc.w.Write([]byte("\u000a")); err != nil {
34 | return err
35 | }
36 | return nil
37 | }
38 |
--------------------------------------------------------------------------------
/rfc7464/json_test.go:
--------------------------------------------------------------------------------
1 | package rfc7464
2 |
3 | import (
4 | "bytes"
5 | "testing"
6 | )
7 |
8 | func TestEncode(t *testing.T) {
9 | out := bytes.NewBuffer(nil)
10 | NewEncoder(out).Encode(map[string]int{
11 | "foo": 1, "bar": 2, "baz": 3})
12 | actual := string(out.Bytes())
13 | expected := "\u001e" + "{\"bar\":2,\"baz\":3,\"foo\":1}" + "\u000a"
14 | if actual != expected {
15 | t.Errorf("Expecting '%s', but got '%s'", expected, actual)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/status/statistics.go:
--------------------------------------------------------------------------------
1 | package status
2 |
3 | import (
4 | "fmt"
5 | "io"
6 | "os"
7 |
8 | "github.com/simon04/aur-out-of-date/rfc7464"
9 | )
10 |
11 | var statisticsWriter io.Writer = os.Stdout
12 |
13 | // Statistics collects package status
14 | type Statistics struct {
15 | Type string `json:"type"`
16 | UpToDate int `json:"up_to_date"`
17 | FlaggedOutOfDate int `json:"flagged_out_of_date"`
18 | OutOfDate int `json:"out_of_date"`
19 | Unknown int `json:"unknown"`
20 | }
21 |
22 | // Update the statistics with another status
23 | func (s *Statistics) Update(status StatusType) {
24 | switch status {
25 | case UpToDate:
26 | s.UpToDate++
27 | case FlaggedOutOfDate:
28 | s.FlaggedOutOfDate++
29 | case OutOfDate:
30 | s.OutOfDate++
31 | case Unknown:
32 | s.Unknown++
33 | }
34 | }
35 |
36 | // Print displays the statistics on the console
37 | func (s *Statistics) Print() {
38 | fmt.Fprintln(statisticsWriter)
39 | fmt.Fprintln(statisticsWriter, "STATISTICS")
40 | fmt.Fprintf(statisticsWriter, "%s%22s %d \x1b[0m\n", UpToDate.color(), "["+UpToDate+"]", s.UpToDate)
41 | fmt.Fprintf(statisticsWriter, "%s%22s %d \x1b[0m\n", FlaggedOutOfDate.color(), "["+FlaggedOutOfDate+"]", s.FlaggedOutOfDate)
42 | fmt.Fprintf(statisticsWriter, "%s%22s %d \x1b[0m\n", OutOfDate.color(), "["+OutOfDate+"]", s.OutOfDate)
43 | fmt.Fprintf(statisticsWriter, "%s%22s %d \x1b[0m\n", Unknown.color(), "["+Unknown+"]", s.Unknown)
44 | fmt.Fprintf(statisticsWriter, "%s%22s %d \x1b[0m\n", Unknown.color(), "[TOTAL]", s.UpToDate+s.FlaggedOutOfDate+s.OutOfDate+s.Unknown)
45 | }
46 |
47 | // PrintJSONTextSequence outputs the statistics as JSON Text Sequences (RFC 7464)
48 | func (s *Statistics) PrintJSONTextSequence() {
49 | s.Type = "statistics"
50 | rfc7464.NewEncoder(statisticsWriter).Encode(s)
51 | }
52 |
--------------------------------------------------------------------------------
/status/statistics_test.go:
--------------------------------------------------------------------------------
1 | package status
2 |
3 | import (
4 | "bytes"
5 | "strings"
6 | "testing"
7 | )
8 |
9 | var stat = Statistics{
10 | UpToDate: 2,
11 | FlaggedOutOfDate: 3,
12 | OutOfDate: 5,
13 | Unknown: 7,
14 | }
15 |
16 | func TestStatisticsOutput(t *testing.T) {
17 | out := bytes.NewBuffer(nil)
18 | statisticsWriter = out
19 | stat.Print()
20 | actual := string(out.Bytes())
21 |
22 | if !strings.Contains(actual, "[UP-TO-DATE] 2") ||
23 | !strings.Contains(actual, "[FLAGGED-OUT-OF-DATE] 3") ||
24 | !strings.Contains(actual, "[OUT-OF-DATE] 5") ||
25 | !strings.Contains(actual, "[UNKNOWN] 7") ||
26 | !strings.Contains(actual, "[TOTAL] 17") {
27 | t.Errorf("Unexpected '%s'", actual)
28 | }
29 | }
30 |
31 | func TestStatisticsJSONOutput(t *testing.T) {
32 | out := bytes.NewBuffer(nil)
33 | statisticsWriter = out
34 | stat.PrintJSONTextSequence()
35 | actual := string(out.Bytes())
36 | expected := "\u001e" + `{"type":"statistics","up_to_date":2,"flagged_out_of_date":3,"out_of_date":5,"unknown":7}` + "\u000a"
37 | if actual != expected {
38 | t.Errorf("Expecting '%s', but got '%s'", expected, actual)
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/status/status.go:
--------------------------------------------------------------------------------
1 | package status
2 |
3 | import (
4 | "fmt"
5 | "io"
6 | "os"
7 |
8 | pkgbuild "github.com/mikkeloscar/gopkgbuild"
9 | "github.com/simon04/aur-out-of-date/rfc7464"
10 | "github.com/simon04/aur-out-of-date/upstream"
11 | )
12 |
13 | var statusWriter io.Writer = os.Stdout
14 |
15 | // StatusType represens the package up-to-date state
16 | type StatusType string
17 |
18 | // UpToDate means that the packaged version matches the upstream version
19 | const UpToDate = StatusType("UP-TO-DATE")
20 |
21 | // FlaggedOutOfDate means that package is outdated and flagged
22 | const FlaggedOutOfDate = StatusType("FLAGGED-OUT-OF-DATE")
23 |
24 | // OutOfDate means that package is outdated
25 | const OutOfDate = StatusType("OUT-OF-DATE")
26 |
27 | // Unknown represents an unknown upstream version
28 | const Unknown = StatusType("UNKNOWN")
29 |
30 | // Status holds the packaged and upstream version for a package
31 | type Status struct {
32 | Type string `json:"type"`
33 | Package string `json:"name"`
34 | Message string `json:"message"`
35 | FlaggedOutOfDate bool `json:"flagged,omitempty"`
36 | Ignored bool `json:"ignored,omitempty"`
37 | Version string `json:"version,omitempty"`
38 | Upstream upstream.Version `json:"upstream,omitempty"`
39 | Status StatusType `json:"status"`
40 | }
41 |
42 | // Compare to upstream version and set message and status accordingly
43 | func (s *Status) Compare(upstreamVersion upstream.Version) {
44 | pkgVersion, err := pkgbuild.NewCompleteVersion(s.Version)
45 | if err != nil {
46 | s.Status = Unknown
47 | s.Message = fmt.Sprintf("Failed to parse pkg version: %v", err)
48 | return
49 | }
50 |
51 | if upstreamVersion.String() == string(pkgVersion.Version) {
52 | s.Status = UpToDate
53 | s.Message = fmt.Sprintf("matches upstream version %v", upstreamVersion)
54 | s.Upstream = upstreamVersion
55 | return
56 | }
57 |
58 | upstreamCompleteVersion, err := pkgbuild.NewCompleteVersion(upstreamVersion.String())
59 | if err != nil {
60 | s.Status = Unknown
61 | s.Message = fmt.Sprintf("Failed to parse upstream version: %v", err)
62 | return
63 | }
64 | s.Upstream = upstreamVersion
65 |
66 | newer := upstreamCompleteVersion.Newer(pkgVersion)
67 | if s.FlaggedOutOfDate {
68 | s.Status = FlaggedOutOfDate
69 | s.Message = fmt.Sprintf("has been flagged out-of-date and should be updated to %v", upstreamVersion)
70 | } else if newer && s.Ignored {
71 | s.Status = Unknown
72 | s.Message = fmt.Sprintf("ignoring package upgrade to %v", upstreamVersion)
73 | } else if newer {
74 | s.Status = OutOfDate
75 | s.Message = fmt.Sprintf("should be updated to %v", upstreamVersion)
76 | } else if upstreamCompleteVersion.Equal(pkgVersion) {
77 | s.Status = UpToDate
78 | s.Message = fmt.Sprintf("matches upstream version %v", upstreamVersion)
79 | } else {
80 | s.Status = Unknown
81 | s.Message = fmt.Sprintf("upstream version is %v", upstreamVersion)
82 | }
83 | }
84 |
85 | func (status StatusType) color() string {
86 | switch status {
87 | case UpToDate:
88 | return "\x1b[32m"
89 | case FlaggedOutOfDate:
90 | return "\x1b[31m"
91 | case OutOfDate:
92 | return "\x1b[31m"
93 | default:
94 | return "\x1b[37m"
95 | }
96 | }
97 |
98 | // Print displays the status on the console
99 | func (s *Status) Print() {
100 | ansiColor := s.Status.color()
101 | fmt.Fprintf(statusWriter, "%s%22s [%s][%s] %s \x1b[0m\n", ansiColor, "["+s.Status+"]", s.Package, s.Version, s.Message)
102 | }
103 |
104 | // PrintJSONTextSequence outputs the status as JSON Text Sequences (RFC 7464)
105 | func (s *Status) PrintJSONTextSequence() {
106 | s.Type = "package"
107 | rfc7464.NewEncoder(statusWriter).Encode(s)
108 | }
109 |
--------------------------------------------------------------------------------
/status/status_test.go:
--------------------------------------------------------------------------------
1 | package status
2 |
3 | import (
4 | "bytes"
5 | "testing"
6 |
7 | "github.com/simon04/aur-out-of-date/upstream"
8 | )
9 |
10 | var s = Status{
11 | Package: "spectre-meltdown-checker",
12 | Version: "0.35-1",
13 | }
14 |
15 | func TestCompare(t *testing.T) {
16 | s.Compare(upstream.Version("0.35"))
17 | if s.Status != UpToDate {
18 | t.Errorf("Expecting status to be %s", UpToDate)
19 | }
20 | s.Compare(upstream.Version("0.37"))
21 | if s.Status != OutOfDate {
22 | t.Errorf("Expecting status to be %s", OutOfDate)
23 | }
24 | s.Compare(upstream.Version("0.30"))
25 | if s.Status != Unknown {
26 | t.Errorf("Expecting status to be %s", Unknown)
27 | }
28 | s.Compare(upstream.Version("foo"))
29 | if s.Status != Unknown {
30 | t.Errorf("Expecting status to be %s", Unknown)
31 | }
32 | }
33 |
34 | func TestStatusOutput(t *testing.T) {
35 | s.Compare(upstream.Version("0.35"))
36 | out := bytes.NewBuffer(nil)
37 | statusWriter = out
38 | s.Print()
39 | actual := string(out.Bytes())
40 | expected := "\x1b[32m [UP-TO-DATE] [spectre-meltdown-checker][0.35-1] matches upstream version 0.35 \x1b[0m\n"
41 | if actual != expected {
42 | t.Errorf("Expecting '%s', but got '%s'", expected, actual)
43 | }
44 | }
45 |
46 | func TestStatusJSONOutput(t *testing.T) {
47 | s.Compare(upstream.Version("0.35"))
48 | out := bytes.NewBuffer(nil)
49 | statusWriter = out
50 | s.PrintJSONTextSequence()
51 | actual := string(out.Bytes())
52 | expected := "\u001e" + `{"type":"package","name":"spectre-meltdown-checker","message":"matches upstream version 0.35","version":"0.35-1","upstream":"0.35","status":"UP-TO-DATE"}` + "\u000a"
53 | if actual != expected {
54 | t.Errorf("Expecting '%s', but got '%s'", expected, actual)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/upstream/debian.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "fmt"
5 | "net/url"
6 | "regexp"
7 | )
8 |
9 | type debianVersion struct {
10 | Version string `json:"version"`
11 | }
12 |
13 | type debianResponse struct {
14 | Versions []debianVersion `json:"versions"`
15 | }
16 |
17 | type debian string
18 |
19 | func (d debian) releasesURL() string {
20 | // API documentation: https://sources.debian.org/doc/api/
21 | return fmt.Sprintf("https://sources.debian.org/api/src/%s/", url.PathEscape(string(d)))
22 | }
23 |
24 | func (d debian) latestVersion() (Version, error) {
25 | var res debianResponse
26 | if err := fetchJSON(d, &res); err != nil {
27 | return "", fmt.Errorf("No debian release found for %v: %w", d, err)
28 | }
29 | match := regexp.MustCompile("([^-]+)[-|~]").FindStringSubmatch(res.Versions[0].Version)
30 | if len(match) > 0 {
31 | return Version(match[1]), nil
32 | }
33 | return Version(res.Versions[0].Version), nil
34 | }
35 |
--------------------------------------------------------------------------------
/upstream/debian_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 |
7 | "github.com/h2non/gock"
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | )
10 |
11 | func mockDebian() *gock.Response {
12 | return gock.New("https://sources.debian.org").
13 | Get("/api/src/babeltrace/").
14 | Reply(http.StatusOK).
15 | SetHeader("Content-Type", "application/json").
16 | BodyString(`
17 | {
18 | "package": "babeltrace",
19 | "path": "babeltrace",
20 | "pathl": [
21 | [
22 | "babeltrace",
23 | "/src/babeltrace/"
24 | ]
25 | ],
26 | "suite": "",
27 | "type": "package",
28 | "versions": [
29 | {
30 | "area": "main",
31 | "suites": [
32 | "buster",
33 | "sid"
34 | ],
35 | "version": "1.5.6-1"
36 | },
37 | {
38 | "area": "main",
39 | "suites": [
40 | "stretch"
41 | ],
42 | "version": "1.5.1-1"
43 | },
44 | {
45 | "area": "main",
46 | "suites": [
47 | "jessie",
48 | "jessie-kfreebsd"
49 | ],
50 | "version": "1.2.3-2"
51 | }
52 | ]
53 | }`)
54 | }
55 |
56 | func TestDebianSource1(t *testing.T) {
57 | defer gock.Off()
58 | mockDebian()
59 |
60 | p := pkg.New("babeltrace", "0", "", "http://debian.backend.mirrors.debian.org/debian/pool/main/b/babeltrace/python3-babeltrace_1.5.6-1_hurd-i386.deb")
61 | version, err := VersionForPkg(p)
62 | if err != nil {
63 | t.Error(err)
64 | }
65 | if version != "1.5.6" {
66 | t.Errorf("Expecting version 1.5.6, but got %v", version)
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/upstream/gitea.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "net/http"
7 | "regexp"
8 | )
9 |
10 | type gitea struct {
11 | Host string
12 | Owner string
13 | Repostiory string
14 | }
15 |
16 | type giteaRelease struct {
17 | Name string `json:"name"`
18 | TagName string `json:"tag_name"`
19 | Draft bool `json:"draft"`
20 | Prerelease bool `json:"prerelease"`
21 | }
22 |
23 | func parseGitea(host string, url string) *gitea {
24 | regex := fmt.Sprintf("%s/([^/#]+)/([^/#]+)", host)
25 | match := regexp.MustCompile(regex).FindStringSubmatch(url)
26 | if len(match) > 0 {
27 | return &gitea{host, match[1], match[2]}
28 | }
29 | return nil
30 | }
31 |
32 | func (g *gitea) latestVersion() (Version, error) {
33 | var releases []giteaRelease
34 | releaseURL := fmt.Sprintf("https://%s/api/v1/repos/%s/%s/releases", g.Host, g.Owner, g.Repostiory)
35 | resp, err := http.Get(releaseURL)
36 | if err != nil {
37 | return "", err
38 | }
39 | defer resp.Body.Close()
40 |
41 | dec := json.NewDecoder(resp.Body)
42 | err = dec.Decode(&releases)
43 | if err != nil {
44 | return "", err
45 | }
46 | for _, release := range releases {
47 | if !release.Prerelease && !release.Draft {
48 | return Version(release.TagName), nil
49 | }
50 | }
51 | return "", fmt.Errorf("No Gitea tag found for %s", g)
52 | }
53 |
--------------------------------------------------------------------------------
/upstream/gitea_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 |
7 | "github.com/h2non/gock"
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | )
10 |
11 | func mockCodeberg() *gock.Response {
12 | return gock.New("https://codeberg.org").
13 | Get("/api/v1/repos/Anoxinon_e.V./xmppc/releases").
14 | Reply(http.StatusOK).
15 | SetHeader("Content-Type", "application/json; charset=UTF-8").
16 | BodyString(`
17 | [
18 | {
19 | "id": 409858,
20 | "tag_name": "0.1.0",
21 | "target_commitish": "master",
22 | "name": "xmppc Version 0.1.0",
23 | "body": "* Support Account configuration with and without pwd (ask user to enter pwd)\r\n* Request roster list\r\n* Show MAM - XEP-0313: Message Archive Management\r\n* Show Bookmarks - XEP-0048: Bookmarks\r\n* Request Service Discovery items and info - XEP-0030: Service Discovery\r\n* Display OMEMO device list and fingerprints (URI format)\r\n* Send chat message (unencrypted) \r\n* Send chat message signcrypted - XEP-0373: OpenPGP for XMPP\r\n* Send chat mesage pgp - XEP-0027\r\n* Monitor XMPP stanza \r\n",
24 | "url": "https://codeberg.org/api/v1/repos/Anoxinon_e.V./xmppc/releases/409858",
25 | "html_url": "https://codeberg.org/Anoxinon_e.V./xmppc/releases/tag/0.1.0",
26 | "tarball_url": "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.1.0.tar.gz",
27 | "zipball_url": "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.1.0.zip",
28 | "draft": true,
29 | "prerelease": false,
30 | "created_at": "2020-05-16T18:19:05+02:00",
31 | "published_at": "2020-05-16T18:19:05+02:00",
32 | "author": {
33 | "id": 558,
34 | "login": "DebXWoody",
35 | "full_name": "",
36 | "email": "debxwoody@noreply.codeberg.org",
37 | "avatar_url": "https://codeberg.org/user/avatar/DebXWoody/-1",
38 | "language": "en-US",
39 | "is_admin": false,
40 | "last_login": "2021-04-24T10:32:42+02:00",
41 | "created": "2019-04-01T08:11:02+02:00",
42 | "username": "DebXWoody"
43 | },
44 | "assets": []
45 | },
46 | {
47 | "id": 409512,
48 | "tag_name": "0.0.6",
49 | "target_commitish": "master",
50 | "name": "xmppc Version 0.0.6",
51 | "body": "BugFix - OpenPGP\r\n\r\n* https://codeberg.org/Anoxinon_e.V./xmppc/issues/7\r\n* https://codeberg.org/Anoxinon_e.V./xmppc/issues/8",
52 | "url": "https://codeberg.org/api/v1/repos/Anoxinon_e.V./xmppc/releases/409512",
53 | "html_url": "https://codeberg.org/Anoxinon_e.V./xmppc/releases/tag/0.0.6",
54 | "tarball_url": "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.0.6.tar.gz",
55 | "zipball_url": "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.0.6.zip",
56 | "draft": false,
57 | "prerelease": true,
58 | "created_at": "2020-05-02T16:05:33+02:00",
59 | "published_at": "2020-05-02T16:05:33+02:00",
60 | "author": {
61 | "id": 558,
62 | "login": "DebXWoody",
63 | "full_name": "",
64 | "email": "debxwoody@noreply.codeberg.org",
65 | "avatar_url": "https://codeberg.org/user/avatar/DebXWoody/-1",
66 | "language": "en-US",
67 | "is_admin": false,
68 | "last_login": "2021-04-24T10:32:42+02:00",
69 | "created": "2019-04-01T08:11:02+02:00",
70 | "username": "DebXWoody"
71 | },
72 | "assets": []
73 | },
74 | {
75 | "id": 409241,
76 | "tag_name": "0.0.5",
77 | "target_commitish": "master",
78 | "name": "xmppc Version 0.0.5",
79 | "body": "xmppc Version 0.0.5\r\n\r\n * XEP-0313: Message Archive Management\r\n * XEP-0048: Bookmarks\r\n * XEP-0030: Service Discovery",
80 | "url": "https://codeberg.org/api/v1/repos/Anoxinon_e.V./xmppc/releases/409241",
81 | "html_url": "https://codeberg.org/Anoxinon_e.V./xmppc/releases/tag/0.0.5",
82 | "tarball_url": "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.0.5.tar.gz",
83 | "zipball_url": "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.0.5.zip",
84 | "draft": false,
85 | "prerelease": false,
86 | "created_at": "2020-04-25T06:25:32+02:00",
87 | "published_at": "2020-04-25T06:25:32+02:00",
88 | "author": {
89 | "id": 558,
90 | "login": "DebXWoody",
91 | "full_name": "",
92 | "email": "debxwoody@noreply.codeberg.org",
93 | "avatar_url": "https://codeberg.org/user/avatar/DebXWoody/-1",
94 | "language": "en-US",
95 | "is_admin": false,
96 | "last_login": "2021-04-24T10:32:42+02:00",
97 | "created": "2019-04-01T08:11:02+02:00",
98 | "username": "DebXWoody"
99 | },
100 | "assets": []
101 | },
102 | {
103 | "id": 409065,
104 | "tag_name": "0.0.4",
105 | "target_commitish": "master",
106 | "name": "xmppc Version 0.0.4",
107 | "body": "* Config file for accounts\r\n* Changed output format of omemo list to URL format\r\n* Bugfixes for OpenPGP / PGP Key lookup\r\n",
108 | "url": "https://codeberg.org/api/v1/repos/Anoxinon_e.V./xmppc/releases/409065",
109 | "html_url": "https://codeberg.org/Anoxinon_e.V./xmppc/releases/tag/0.0.4",
110 | "tarball_url": "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.0.4.tar.gz",
111 | "zipball_url": "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.0.4.zip",
112 | "draft": false,
113 | "prerelease": false,
114 | "created_at": "2020-04-21T18:23:40+02:00",
115 | "published_at": "2020-04-21T18:23:40+02:00",
116 | "author": {
117 | "id": 558,
118 | "login": "DebXWoody",
119 | "full_name": "",
120 | "email": "debxwoody@noreply.codeberg.org",
121 | "avatar_url": "https://codeberg.org/user/avatar/DebXWoody/-1",
122 | "language": "en-US",
123 | "is_admin": false,
124 | "last_login": "2021-04-24T10:32:42+02:00",
125 | "created": "2019-04-01T08:11:02+02:00",
126 | "username": "DebXWoody"
127 | },
128 | "assets": []
129 | }
130 | ]
131 | `)
132 | }
133 |
134 | func TestGiteaSource(t *testing.T) {
135 | defer gock.Off()
136 | mockCodeberg()
137 |
138 | p := pkg.New("xmppc", "0", "https://codeberg.org/Anoxinon_e.V./xmppc", "https://codeberg.org/Anoxinon_e.V./xmppc/archive/0.1.0.tar.gz")
139 | version, err := VersionForPkg(p)
140 | if err != nil {
141 | t.Error(err)
142 | }
143 | if version.String() != "0.0.5" {
144 | t.Errorf("Expecting version 0.0.5, but got %v", version)
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/upstream/github.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "net/http"
7 | "os"
8 | "regexp"
9 | )
10 |
11 | type gitHub struct {
12 | owner string
13 | repository string
14 | }
15 |
16 | func (g gitHub) String() string {
17 | return g.owner + "/" + g.repository
18 | }
19 |
20 | func parseGitHub(url string) *gitHub {
21 | match := regexp.MustCompile("github.com/([^/#.]+)/([^/#]+)").FindStringSubmatch(url)
22 | if len(match) > 0 {
23 | return &gitHub{match[1], match[2]}
24 | }
25 | match = regexp.MustCompile("([^/#.]+).github.io/([^/#]+)").FindStringSubmatch(url)
26 | if len(match) > 0 {
27 | return &gitHub{match[1], match[2]}
28 | }
29 | return nil
30 | }
31 |
32 | func (g gitHub) request(url string, target interface{}) error {
33 | req, err := http.NewRequest("GET", url, nil)
34 |
35 | // Obtain GitHub token for higher request limits, see https://developer.github.com/v3/#rate-limiting
36 | token := os.Getenv("GITHUB_TOKEN")
37 | if token != "" {
38 | req.Header.Set("Authorization", "token "+token)
39 | }
40 | if err != nil {
41 | return err
42 | }
43 |
44 | resp, err := http.DefaultClient.Do(req)
45 | if err != nil {
46 | return err
47 | }
48 | defer resp.Body.Close()
49 |
50 | dec := json.NewDecoder(resp.Body)
51 | if resp.StatusCode == http.StatusForbidden {
52 | var message gitHubMessage
53 | err = dec.Decode(&message)
54 | if err == nil && message.Message != "" {
55 | err = fmt.Errorf("%s", message.Message)
56 | }
57 | return err
58 | } else if resp.StatusCode == http.StatusNotFound {
59 | return fmt.Errorf("No GitHub project found for %s on %s", g, url)
60 | }
61 | return dec.Decode(target)
62 | }
63 |
--------------------------------------------------------------------------------
/upstream/github_atom.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "encoding/xml"
5 | "fmt"
6 | "net/http"
7 | "net/url"
8 | "regexp"
9 | )
10 |
11 | type gitHubAPIAtom struct {
12 | gitHub
13 | }
14 |
15 | type atomFeed struct {
16 | Items []atomEntry `xml:"entry"`
17 | }
18 |
19 | type atomEntry struct {
20 | Link atomLink `xml:"link"`
21 | }
22 |
23 | type atomLink struct {
24 | Href string `xml:"href,attr"`
25 | }
26 |
27 | func (g gitHubAPIAtom) atomURL() string {
28 | return fmt.Sprintf("https://github.com/%s/%s/releases.atom", g.owner, g.repository)
29 | }
30 |
31 | func (g gitHubAPIAtom) errorWrap(err error) error {
32 | return fmt.Errorf("Failed to obtain GitHub release for %s from %s: %w", g.String(), g.atomURL(), err)
33 | }
34 |
35 | func (g gitHubAPIAtom) errorNotFound() error {
36 | return fmt.Errorf("No GitHub release found for %s on %s", g, g.atomURL())
37 | }
38 |
39 | func (g gitHubAPIAtom) latestVersion() (Version, error) {
40 | resp, err := http.Get(g.atomURL())
41 | if err != nil {
42 | return "", g.errorWrap(err)
43 | }
44 | defer resp.Body.Close()
45 |
46 | dec := xml.NewDecoder(resp.Body)
47 | var feed atomFeed
48 | err = dec.Decode(&feed)
49 | if err != nil {
50 | return "", g.errorWrap(err)
51 | } else if len(feed.Items) == 0 {
52 | return "", g.errorNotFound()
53 | }
54 |
55 | href, err := url.PathUnescape(feed.Items[0].Link.Href)
56 | if err != nil {
57 | return "", g.errorWrap(err)
58 | }
59 | link := regexp.MustCompile("/releases/tag/v?(.*)").FindSubmatch([]byte(href))
60 | if link == nil {
61 | return "", g.errorNotFound()
62 | }
63 | version := string(link[1])
64 | return Version(version), nil
65 | }
66 |
--------------------------------------------------------------------------------
/upstream/github_atom_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "os"
6 | "testing"
7 |
8 | "github.com/h2non/gock"
9 | "github.com/simon04/aur-out-of-date/pkg"
10 | )
11 |
12 | func mockGitHubAtom() *gock.Response {
13 | return gock.New("https://github.com/").
14 | Get("/leaflet/leaflet/releases.atom").
15 | Reply(http.StatusOK).
16 | BodyString(`
17 |
18 |
19 | Release notes from Leaflet
20 | 2019-11-17T21:04:59Z
21 |
22 | tag:github.com,2008:Repository/931135/v1.6.0
23 | 2019-11-17T21:12:44Z
24 |
25 | v1.6.0
26 |
27 | cherniavskii
28 |
29 |
30 | `)
31 | }
32 |
33 | func TestLeafletGitHubAtom(t *testing.T) {
34 | defer gock.Off()
35 | mockGitHubAtom()
36 |
37 | os.Setenv("GITHUB_ATOM", "1")
38 | p := pkg.New("leaflet", "0", "https://github.com/leaflet/leaflet")
39 | version, err := VersionForPkg(p)
40 | if err != nil {
41 | t.Error(err)
42 | }
43 | if version.String() != "1.6.0" {
44 | t.Errorf("Expecting version 1.6.0, but got %v", version)
45 | }
46 | os.Unsetenv("GITHUB_ATOM")
47 | }
48 |
--------------------------------------------------------------------------------
/upstream/github_release.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "fmt"
5 | "time"
6 | )
7 |
8 | type gitHubAPIReleases struct {
9 | gitHub
10 | }
11 |
12 | func (g gitHubAPIReleases) releasesURL() string {
13 | // API documentation: https://developer.github.com/v3/repos/releases/
14 | return fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", g.owner, g.repository)
15 | }
16 |
17 | func (g gitHubAPIReleases) errorWrap(err error) error {
18 | return fmt.Errorf("Failed to obtain GitHub release for %s from %s: %w", g.String(), g.releasesURL(), err)
19 | }
20 |
21 | func (g gitHubAPIReleases) errorNotFound() error {
22 | return fmt.Errorf("No GitHub release found for %s on %s", g, g.releasesURL())
23 | }
24 |
25 | type gitHubRelease struct {
26 | URL string `json:"url"`
27 | Name string `json:"name"`
28 | TagName string `json:"tag_name"`
29 | Prerelease bool `json:"prerelease"`
30 | Draft bool `json:"draft"`
31 | PublishedAt time.Time `json:"published_at"`
32 | }
33 |
34 | type gitHubMessage struct {
35 | Message string `json:"message"`
36 | DocumentationURL string `json:"documentation_url"`
37 | }
38 |
39 | func (g gitHubAPIReleases) latestVersion() (Version, error) {
40 | var release gitHubRelease
41 | err := g.request(g.releasesURL(), &release)
42 | if err != nil {
43 | return "", g.errorWrap(err)
44 | } else if release.Prerelease {
45 | return "", fmt.Errorf("Ignoring GitHub pre-release %s for %s", release.Name, g.String())
46 | } else if release.Draft {
47 | return "", fmt.Errorf("Ignoring GitHub release draft %s for %s", release.Name, g.String())
48 | } else if release.TagName != "" {
49 | return Version(release.TagName), nil
50 | } else if release.Name != "" {
51 | return Version(release.Name), nil
52 | }
53 | return "", g.errorNotFound()
54 | }
55 |
--------------------------------------------------------------------------------
/upstream/github_release_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 |
7 | "github.com/h2non/gock"
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | )
10 |
11 | func mockGitHub() *gock.Response {
12 | return gock.New("https://api.github.com/").
13 | Get("/repos/gogits/gogs/releases/latest").
14 | Reply(http.StatusOK).
15 | SetHeader("Content-Type", "application/atom+xml").
16 | BodyString(`
17 | {
18 | "url": "https://api.github.com/repos/gogits/gogs/releases/8625798",
19 | "id": 8625798,
20 | "tag_name": "v0.11.34",
21 | "target_commitish": "master",
22 | "name": "v0.11.34",
23 | "draft": false,
24 | "prerelease": false,
25 | "created_at": "2017-11-22T19:46:14Z",
26 | "published_at": "2017-11-22T19:52:48Z"
27 | }
28 | `)
29 | }
30 |
31 | func TestGogsGitHubUrl(t *testing.T) {
32 | defer gock.Off()
33 | mockGitHub()
34 |
35 | p := pkg.New("gogs", "0", "https://github.com/gogits/gogs")
36 | version, err := VersionForPkg(p)
37 | if err != nil {
38 | t.Error(err)
39 | }
40 | if version.String() != "0.11.34" {
41 | t.Errorf("Expecting version 0.11.34, but got %v", version)
42 | }
43 | }
44 |
45 | func TestGogsGitHubSource(t *testing.T) {
46 | defer gock.Off()
47 | mockGitHub()
48 |
49 | p := pkg.New("gogs", "0", "https://gogs.io/", "https://github.com/gogits/gogs/archive/v0.11.34.tar.gz")
50 | version, err := VersionForPkg(p)
51 | if err != nil {
52 | t.Error(err)
53 | }
54 | if version.String() != "0.11.34" {
55 | t.Errorf("Expecting version 0.11.34, but got %v", version)
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/upstream/github_tags.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type gitHubAPITags struct {
8 | gitHub
9 | }
10 |
11 | func (g gitHubAPITags) tagsURL() string {
12 | // API documentation: https://developer.github.com/v3/repos/#list-tags
13 | return fmt.Sprintf("https://api.github.com/repos/%s/%s/tags", g.owner, g.repository)
14 | }
15 |
16 | func (g gitHubAPITags) errorWrap(err error) error {
17 | return fmt.Errorf("Failed to obtain GitHub tag for %s from %s: %w", g.String(), g.tagsURL(), err)
18 | }
19 |
20 | func (g gitHubAPITags) errorNotFound() error {
21 | return fmt.Errorf("No GitHub tag found for %s on %s", g, g.tagsURL())
22 | }
23 |
24 | type gitHubTag struct {
25 | Name string `json:"name"`
26 | }
27 |
28 | func (g gitHubAPITags) latestVersion() (Version, error) {
29 | var taglist []gitHubTag
30 | err := g.request(g.tagsURL(), &taglist)
31 | if err != nil {
32 | return "", g.errorWrap(err)
33 | } else if len(taglist) > 0 {
34 | if taglist[0].Name != "" {
35 | return Version(taglist[0].Name), nil
36 | }
37 | }
38 | return "", g.errorNotFound()
39 | }
40 |
--------------------------------------------------------------------------------
/upstream/github_tags_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "os"
6 | "testing"
7 |
8 | "github.com/h2non/gock"
9 | "github.com/simon04/aur-out-of-date/pkg"
10 | )
11 |
12 | func mockGitHubTags() *gock.Response {
13 | return gock.New("https://api.github.com/").
14 | Get("/repos/gogits/gogs/tags").
15 | Reply(http.StatusOK).
16 | BodyString(`
17 | [
18 | {
19 | "name": "v0.11.34",
20 | "zipball_url": "https://api.github.com/repos/gogs/gogs/zipball/v0.11.34",
21 | "tarball_url": "https://api.github.com/repos/gogs/gogs/tarball/v0.11.34",
22 | "commit": {
23 | "sha": "6f2347fc71f17b5703a9b1f383a2d3451f88b741",
24 | "url": "https://api.github.com/repos/gogs/gogs/commits/6f2347fc71f17b5703a9b1f383a2d3451f88b741"
25 | },
26 | "node_id": "MDM6UmVmMTY3NTI2MjA6djAuMTEuMzQ="
27 | },
28 | {
29 | "name": "v0.11.33",
30 | "zipball_url": "https://api.github.com/repos/gogs/gogs/zipball/v0.11.33",
31 | "tarball_url": "https://api.github.com/repos/gogs/gogs/tarball/v0.11.33",
32 | "commit": {
33 | "sha": "b752fe680811119954ccef051e6f3b3e2a04c2e8",
34 | "url": "https://api.github.com/repos/gogs/gogs/commits/b752fe680811119954ccef051e6f3b3e2a04c2e8"
35 | },
36 | "node_id": "MDM6UmVmMTY3NTI2MjA6djAuMTEuMzM="
37 | }
38 | ]`)
39 | }
40 |
41 | func TestGogsGitHubTags(t *testing.T) {
42 | defer gock.Off()
43 | mockGitHubTags()
44 |
45 | os.Setenv("GITHUB_TAGS", "1")
46 | p := pkg.New("gogs", "0", "https://github.com/gogits/gogs")
47 | version, err := VersionForPkg(p)
48 | if err != nil {
49 | t.Error(err)
50 | }
51 | if version.String() != "0.11.34" {
52 | t.Errorf("Expecting version 0.11.34, but got %v", version)
53 | }
54 | os.Unsetenv("GITHUB_TAGS")
55 | }
56 |
--------------------------------------------------------------------------------
/upstream/github_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestParseGitHub(t *testing.T) {
8 | g := parseGitHub("https://github.com/foo/bar")
9 | if g.owner != "foo" || g.repository != "bar" {
10 | t.Errorf("Expecting foo/bar, but got %v", g.String())
11 | }
12 | g = parseGitHub("https://foo.github.io/bar/...")
13 | if g.owner != "foo" || g.repository != "bar" {
14 | t.Errorf("Expecting foo/bar, but got %v", g.String())
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/upstream/gitlab.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "net/http"
7 | "net/url"
8 | "os"
9 | )
10 |
11 | // Self-hosted GitLab instances use different domain names
12 | type gitLab struct {
13 | domain string
14 | owner string
15 | repository string
16 | }
17 |
18 | func (g gitLab) String() string {
19 | return g.domain + "/" + g.owner + "/" + g.repository
20 | }
21 |
22 | func (g gitLab) encoded() string {
23 | // GitLab requires the owner + repository to be url-encoded together
24 | return url.PathEscape(g.owner) + "%2F" + url.PathEscape(g.repository)
25 | }
26 |
27 | func (g gitLab) releasesURL() string {
28 | // API documentation: https://docs.gitlab.com/ee/api/tags.html#list-project-repository-tags
29 | // Note that the second %s must be url-encoded (see gitLab.encoded())
30 | return fmt.Sprintf("https://%s/api/v4/projects/%s/repository/tags", g.domain, g.encoded())
31 | }
32 |
33 | func (g gitLab) errorWrap(err error) error {
34 | return fmt.Errorf("Failed to obtain GitLab tag for %s from %s: %w", g.String(), g.releasesURL(), err)
35 | }
36 |
37 | func (g gitLab) errorNotFound() error {
38 | return fmt.Errorf("No GitLab release found for %s on %s", g, g.releasesURL())
39 | }
40 |
41 | // Describes the individual tags in the returned taglist from the json call
42 | type gitLabTag struct {
43 | Name string `json:"name"`
44 | }
45 |
46 | type gitLabMessage struct {
47 | Message string `json:"message"`
48 | }
49 |
50 | func (g gitLab) latestVersion() (Version, error) {
51 | req, err := http.NewRequest("GET", g.releasesURL(), nil)
52 |
53 | // Obtain GitLab token for higher request limits, see https://docs.gitlab.com/ee/api/#oauth2-tokens
54 | token := os.Getenv("GITLAB_TOKEN")
55 | if token != "" {
56 | req.Header.Set("Authorization", "Bearer "+token)
57 | }
58 | if err != nil {
59 | return "", g.errorWrap(err)
60 | }
61 |
62 | resp, err := http.DefaultClient.Do(req)
63 | if err != nil {
64 | return "", g.errorWrap(err)
65 | }
66 | defer resp.Body.Close()
67 |
68 | dec := json.NewDecoder(resp.Body)
69 | if resp.StatusCode == http.StatusForbidden {
70 | var message gitLabMessage
71 | err = dec.Decode(&message)
72 | if err == nil && message.Message != "" {
73 | err = fmt.Errorf("%s", message.Message)
74 | }
75 | return "", g.errorWrap(err)
76 | } else if resp.StatusCode == http.StatusNotFound {
77 | return "", g.errorNotFound()
78 | }
79 |
80 | // Can't get single tag, has to be an array
81 | // NOTE: If GitLab ever adds a "get newest tag" API call then change this
82 | var taglist []gitLabTag
83 | err = dec.Decode(&taglist)
84 | if err != nil {
85 | return "", g.errorWrap(err)
86 | } else if len(taglist) > 0 {
87 | // [0] will always be the newest, as its sorted by default
88 | if taglist[0].Name != "" {
89 | return Version(taglist[0].Name), nil
90 | }
91 | }
92 | return "", g.errorNotFound()
93 | }
94 |
--------------------------------------------------------------------------------
/upstream/gitlab_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 |
7 | "github.com/h2non/gock"
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | )
10 |
11 | func mockGitLab() *gock.Response {
12 | return gock.New("https://gitlab.com").
13 | Get("/api/v4/projects/gitlab-org/gitlab-ce/repository/tags").
14 | Reply(http.StatusOK).
15 | SetHeader("Content-Type", "application/json").
16 | // Since it always returns a taglist, added 2 to the return
17 | BodyString(`
18 | [
19 | {
20 | "name": "v11.0.0-rc13",
21 | "message": "Version v11.0.0-rc13",
22 | "target": "162a86504a9c56dc142aab8bb6beeeaca29a6b86",
23 | "commit": {
24 | "id": "0a9f160f39d47948a0a011907a7d0e989df3cd69",
25 | "short_id": "0a9f160f",
26 | "title": "Update VERSION to 11.0.0-rc13",
27 | "created_at": "2018-06-18T11:55:51.000Z",
28 | "parent_ids": [
29 | "b020eb1e15bc8323affe372cf9f713e3b3ae27ad"
30 | ],
31 | "message": "Update VERSION to 11.0.0-rc13\n",
32 | "author_name": "GitLab Release Tools Bot",
33 | "author_email": "robert+release-tools@gitlab.com",
34 | "authored_date": "2018-06-18T11:55:51.000Z",
35 | "committer_name": "GitLab Release Tools Bot",
36 | "committer_email": "robert+release-tools@gitlab.com",
37 | "committed_date": "2018-06-18T11:55:51.000Z"
38 | },
39 | "release": null
40 | },
41 | {
42 | "name": "v11.0.0-rc12",
43 | "message": "Version v11.0.0-rc12",
44 | "target": "6dc273b4f9881e0c90524bd478dad3bba126ab86",
45 | "commit": {
46 | "id": "44f330568c3fee5c28224d0eb4d6e4e0fe46be53",
47 | "short_id": "44f33056",
48 | "title": "Update VERSION to 11.0.0-rc12",
49 | "created_at": "2018-06-14T12:56:56.000Z",
50 | "parent_ids": [
51 | "99dfb12a912c5d38074a5c352d5ff76781e6f2cc"
52 | ],
53 | "message": "Update VERSION to 11.0.0-rc12\n",
54 | "author_name": "GitLab Release Tools Bot",
55 | "author_email": "robert+release-tools@gitlab.com",
56 | "authored_date": "2018-06-14T12:56:56.000Z",
57 | "committer_name": "GitLab Release Tools Bot",
58 | "committer_email": "robert+release-tools@gitlab.com",
59 | "committed_date": "2018-06-14T12:56:56.000Z"
60 | },
61 | "release": null
62 | }
63 | ]
64 | `)
65 | }
66 |
67 | func TestGitLabceGitLabSource(t *testing.T) {
68 | defer gock.Off()
69 | mockGitLab()
70 |
71 | p := pkg.New("gitlab-ce", "0", "https://gitlab.com/gitlab-org/gitlab-ce", "https://gitlab.com/gitlab-org/gitlab-ce/-/archive/v11.0.0-rc13/gitlab-ce-v11.0.0-rc13.tar.gz")
72 | version, err := VersionForPkg(p)
73 | if err != nil {
74 | t.Error(err)
75 | }
76 | if version.String() != "11.0.0-rc13" {
77 | t.Errorf("Expecting version 11.0.0-rc13, but got %v", version)
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/upstream/npmjs.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "fmt"
5 | "net/url"
6 | )
7 |
8 | type npmDistTags struct {
9 | Latest string `json:"latest"`
10 | }
11 |
12 | type npm string
13 |
14 | func (n npm) releasesURL() string {
15 | // API documentation: https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md
16 | return fmt.Sprintf("https://registry.npmjs.org/-/package/%s/dist-tags", url.PathEscape(string(n)))
17 | }
18 |
19 | func (n npm) latestVersion() (Version, error) {
20 | var distTags npmDistTags
21 | if err := fetchJSON(n, &distTags); err != nil || distTags.Latest == "" {
22 | return "", fmt.Errorf("No npm release found for %v: %w", n, err)
23 | }
24 | return Version(distTags.Latest), nil
25 | }
26 |
--------------------------------------------------------------------------------
/upstream/npmjs_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "testing"
7 |
8 | "github.com/h2non/gock"
9 | "github.com/simon04/aur-out-of-date/pkg"
10 | )
11 |
12 | func mockNpm(version string) *gock.Response {
13 | return gock.New("https://registry.npmjs.org/").
14 | Get("/-/package/webpack/dist-tags").
15 | Reply(http.StatusOK).
16 | SetHeader("Content-Type", "application/json").
17 | BodyString(fmt.Sprintf(`{"latest":"%v","legacy":"1.15.0"}`, version))
18 | }
19 |
20 | func TestWebpackNpmUrl(t *testing.T) {
21 | defer gock.Off()
22 | mockNpm("3.9.0")
23 |
24 | p := pkg.New("webpack", "3.6.0", "https://www.npmjs.com/package/webpack")
25 | version, err := VersionForPkg(p)
26 | if err != nil {
27 | t.Error(err)
28 | }
29 | if version != "3.9.0" {
30 | t.Errorf("Expecting version 3.9.0, but got %v", version)
31 | }
32 | }
33 |
34 | func TestWebpackNpmSource(t *testing.T) {
35 | defer gock.Off()
36 | mockNpm("4.0.0")
37 |
38 | p := pkg.New("webpack", "3.6.0", "https://webpack.js.org/", "http://registry.npmjs.org/webpack/-/webpack-3.6.0.tgz")
39 | version, err := VersionForPkg(p)
40 | if err != nil {
41 | t.Error(err)
42 | }
43 | if version != "4.0.0" {
44 | t.Errorf("Expecting version 4.0.0, but got %v", version)
45 | }
46 | }
47 |
48 | func TestWebpackNoSource(t *testing.T) {
49 | p := pkg.New("webpack", "3.6.0", "https://webpack.js.org/")
50 | _, err := VersionForPkg(p)
51 | if err == nil {
52 | t.Error("Expecting an error, but got none")
53 | }
54 | }
55 |
56 | func TestWebpackUnknownSource(t *testing.T) {
57 | p := pkg.New("webpack", "3.6.0", "https://webpack.js.org/", "http://webpack.js.org/webpack-3.6.0.tgz")
58 | _, err := VersionForPkg(p)
59 | if err == nil {
60 | t.Error("Expecting an error, but got none")
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/upstream/perl.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type cpanRelease struct {
8 | Version string `json:"version"`
9 | }
10 |
11 | type cpan string
12 |
13 | func (p cpan) releasesURL() string {
14 | // API documentation: https://github.com/metacpan/metacpan-api/blob/master/docs/API-docs.md
15 | return fmt.Sprintf("https://fastapi.metacpan.org/v1/release/%s", p)
16 | }
17 |
18 | func (p cpan) latestVersion() (Version, error) {
19 | var info cpanRelease
20 | if err := fetchJSON(p, &info); err != nil || info.Version == "" {
21 | return "", fmt.Errorf("No CPAN release found for %v: %w", p, err)
22 | }
23 | return Version(info.Version), nil
24 | }
25 |
--------------------------------------------------------------------------------
/upstream/perl_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 |
7 | "github.com/h2non/gock"
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | )
10 |
11 | func mockPerl() *gock.Response {
12 | return gock.New("https://fastapi.metacpan.org/").
13 | Get("/v1/release/Perl-Critic").
14 | Reply(http.StatusOK).
15 | SetHeader("Content-Type", "application/json").
16 | BodyString(`{
17 | "main_module" : "Perl::Critic",
18 | "date" : "2017-07-21T04:28:55",
19 | "status" : "latest",
20 | "author" : "PETDANCE",
21 | "distribution" : "Perl-Critic",
22 | "version" : "1.130",
23 | "changes_file" : "Changes",
24 | "name" : "Perl-Critic-1.130"
25 | }`)
26 | }
27 |
28 | func TestPerlSource1(t *testing.T) {
29 | defer gock.Off()
30 | mockPerl()
31 |
32 | p := pkg.New("perl-critic", "0", "", "http://search.cpan.org/CPAN/authors/id/T/TH/THALJEF/Perl-Critic-1.126.tar.gz")
33 | version, err := VersionForPkg(p)
34 | if err != nil {
35 | t.Error(err)
36 | }
37 | if version != "1.130" {
38 | t.Errorf("Expecting version 1.130, but got %v", version)
39 | }
40 | }
41 |
42 | func TestPerlSource2(t *testing.T) {
43 | defer gock.Off()
44 | mockPerl()
45 |
46 | p := pkg.New("perl-critic", "0", "", "https://cpan.metacpan.org/authors/id/P/PE/PETDANCE/Perl-Critic-1.126.tar.gz")
47 | version, err := VersionForPkg(p)
48 | if err != nil {
49 | t.Error(err)
50 | }
51 | if version != "1.130" {
52 | t.Errorf("Expecting version 1.130, but got %v", version)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/upstream/python.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type pypiResponse struct {
8 | Info struct {
9 | Version string `json:"version"`
10 | } `json:"info"`
11 | }
12 |
13 | type pypi string
14 |
15 | func (p pypi) releasesURL() string {
16 | return fmt.Sprintf("https://pypi.org/pypi/%s/json", p)
17 | }
18 |
19 | func (p pypi) latestVersion() (Version, error) {
20 | var response pypiResponse
21 | if err := fetchJSON(p, &response); err != nil || response.Info.Version == "" {
22 | return "", fmt.Errorf("No PyPI release found for %v: %w", p, err)
23 | }
24 | return Version(response.Info.Version), nil
25 | }
26 |
--------------------------------------------------------------------------------
/upstream/python_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 |
7 | "github.com/h2non/gock"
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | )
10 |
11 | func mockPython() *gock.Response {
12 | return gock.New("https://pypi.org/").
13 | Get("/pypi/httpie/json").
14 | Reply(http.StatusOK).
15 | SetHeader("Content-Type", "application/json").
16 | BodyString(`{
17 | "info": {
18 | "package_url": "http://pypi.python.org/pypi/httpie",
19 | "download_url": "https://github.com/jkbrzt/httpie",
20 | "platform": "UNKNOWN",
21 | "version": "0.9.9",
22 | "release_url": "http://pypi.python.org/pypi/httpie/0.9.9"
23 | }
24 | }`)
25 | }
26 |
27 | func TestPythonHttpieSource1(t *testing.T) {
28 | testPythonHttpie(t, "https://pypi.python.org/packages/source/h/httpie/httpie-0.9.9.tar.gz")
29 | }
30 |
31 | func TestPythonHttpieSource2(t *testing.T) {
32 |
33 | }
34 |
35 | func TestPythonHttpieSource3(t *testing.T) {
36 | // URL from https://pypi.org/project/httpie/#files
37 | testPythonHttpie(t, "https://files.pythonhosted.org/packages/28/93/4ebf2de4bc74bd517a27a600b2b23a5254a20f28e6e36fc876fd98f7a51b/httpie-0.9.9.tar.gz")
38 | }
39 |
40 | func testPythonHttpie(t *testing.T, url string) {
41 | defer gock.Off()
42 | mockPython()
43 |
44 | p := pkg.New("httpie", "0", "", url)
45 | version, err := VersionForPkg(p)
46 | if err != nil {
47 | t.Error(err)
48 | }
49 | if version != "0.9.9" {
50 | t.Errorf("Expecting version 0.9.9, but got %v", version)
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/upstream/rubygems.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "fmt"
5 | "time"
6 | )
7 |
8 | type rubygemsVersions []struct {
9 | Authors string `json:"authors"`
10 | BuiltAt time.Time `json:"built_at"`
11 | CreatedAt time.Time `json:"created_at"`
12 | Description string `json:"description"`
13 | DownloadsCount int `json:"downloads_count"`
14 | Number string `json:"number"`
15 | Summary string `json:"summary"`
16 | Platform string `json:"platform"`
17 | RubygemsVersion string `json:"rubygems_version"`
18 | RubyVersion string `json:"ruby_version"`
19 | Prerelease bool `json:"prerelease"`
20 | Licenses []string `json:"licenses"`
21 | Requirements []interface{} `json:"requirements"`
22 | Sha string `json:"sha"`
23 | }
24 |
25 | type rubygem string
26 |
27 | func (g rubygem) releasesURL() string {
28 | return fmt.Sprintf("https://rubygems.org/api/v1/versions/%s.json", g)
29 | }
30 |
31 | func (g rubygem) latestVersion() (Version, error) {
32 | var versions rubygemsVersions
33 | if err := fetchJSON(g, &versions); err != nil || len(versions) == 0 {
34 | return "", fmt.Errorf("No RubyGems release found for %v: %w", g, err)
35 | }
36 | return Version(versions[0].Number), nil
37 | }
38 |
--------------------------------------------------------------------------------
/upstream/rubygems_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "net/http"
5 | "testing"
6 |
7 | "github.com/h2non/gock"
8 | "github.com/simon04/aur-out-of-date/pkg"
9 | )
10 |
11 | func mockRubyGems() *gock.Response {
12 | return gock.New("https://rubygems.org").
13 | Get("/api/v1/versions/htmlbeautifier.json").
14 | Reply(http.StatusOK).
15 | SetHeader("Content-Type", "application/json").
16 | BodyString(`[{
17 | "description": "A normaliser/beautifier for HTML that also understands embedded Ruby.",
18 | "number": "1.3.1",
19 | "summary": "HTML/ERB beautifier",
20 | "licenses": ["MIT"],
21 | "sha": "1af1b96b60969ad4721abe925620baa5aa68a6a77db71af8fe33e77e862b019c"
22 | }]`)
23 | }
24 |
25 | func TestRubyGemsSource1(t *testing.T) {
26 | defer gock.Off()
27 | mockRubyGems()
28 |
29 | p := pkg.New("ruby-htmlbeautifier", "0", "", "https://rubygems.org/downloads/htmlbeautifier-1.3.1.gem")
30 | version, err := VersionForPkg(p)
31 | if err != nil {
32 | t.Error(err)
33 | }
34 | if version != "1.3.1" {
35 | t.Errorf("Expecting version 1.3.1, but got %v", version)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/upstream/version.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "net/http"
7 | "os"
8 | "os/exec"
9 | "regexp"
10 | "strings"
11 |
12 | "github.com/simon04/aur-out-of-date/pkg"
13 | )
14 |
15 | // Version represents the upstream version of a software project
16 | type Version string
17 |
18 | // String returns a sanitized version string
19 | func (v Version) String() string {
20 | s := string(v)
21 | s = strings.TrimLeft(s, "release/")
22 | s = strings.TrimLeft(s, "v")
23 | return s
24 | }
25 |
26 | func forURL(url string) (Version, error) {
27 | switch {
28 | case strings.Contains(url, "github.com"):
29 | fallthrough
30 | case strings.Contains(url, "github.io"):
31 | g := parseGitHub(url)
32 | if g == nil {
33 | break
34 | }
35 | if os.Getenv("GITHUB_ATOM") != "" {
36 | return gitHubAPIAtom{gitHub: *g}.latestVersion()
37 | } else if os.Getenv("GITHUB_TAGS") != "" {
38 | return gitHubAPITags{gitHub: *g}.latestVersion()
39 | }
40 | return gitHubAPIReleases{gitHub: *g}.latestVersion()
41 | case strings.Contains(url, "registry.npmjs.org"):
42 | match := regexp.MustCompile("registry.npmjs.org/((@[^/#.]+/)?[^/#.]+)").FindStringSubmatch(url)
43 | if len(match) > 0 {
44 | return npm(match[1]).latestVersion()
45 | }
46 | case strings.Contains(url, "npmjs.com/package"):
47 | fallthrough
48 | case strings.Contains(url, "npmjs.org/package"):
49 | match := regexp.MustCompile("/package/((@[^/#.]+/)?[^/#.]+)").FindStringSubmatch(url)
50 | if len(match) > 0 {
51 | return npm(match[1]).latestVersion()
52 | }
53 | case strings.Contains(url, "pypi.python.org"):
54 | fallthrough
55 | case strings.Contains(url, "files.pythonhosted.org"):
56 | fallthrough
57 | case strings.Contains(url, "pypi.io"):
58 | fallthrough
59 | case strings.Contains(url, "pypi.org"):
60 | match := regexp.MustCompile("/packages/source/[^/#.]+/([^/#.]+)/").FindStringSubmatch(url)
61 | if len(match) > 0 {
62 | return pypi(match[1]).latestVersion()
63 | }
64 | match = regexp.MustCompile("/([^/#.]+)-[0-9.]+(post.)?.tar.gz$").FindStringSubmatch(url)
65 | if len(match) > 0 {
66 | return pypi(match[1]).latestVersion()
67 | }
68 | case strings.Contains(url, "search.cpan.org"):
69 | fallthrough
70 | case strings.Contains(url, "search.mcpan.org"):
71 | fallthrough
72 | case strings.Contains(url, "cpan.metacpan.org"):
73 | match := regexp.MustCompile("/([^/#.]+?)-v?([0-9.-]+)\\.(tgz|tar.gz)$").FindStringSubmatch(url)
74 | if len(match) > 0 {
75 | return cpan(match[1]).latestVersion()
76 | }
77 | case strings.Contains(url, "rubygems.org"):
78 | fallthrough
79 | case strings.Contains(url, "gems.rubyforge.org"):
80 | match := regexp.MustCompile("/([^/#]+?)-[^-]+\\.gem$").FindStringSubmatch(url)
81 | if len(match) > 0 {
82 | return rubygem(match[1]).latestVersion()
83 | }
84 | case strings.Contains(url, "gitlab"):
85 | // Example: https://gitlab.com/gitlab-org/gitlab-ce/-/archive/v11.0.0-rc7/gitlab-ce-v11.0.0-rc7.tar.gz
86 | match := regexp.MustCompile("https?://([^/]+)/([^/]+)/([^/]+)(\\.git|/.*)?$").FindStringSubmatch(url)
87 | if len(match) > 0 {
88 | return gitLab{match[1], match[2], match[3]}.latestVersion()
89 | }
90 | case strings.Contains(url, "debian.org"):
91 | // Example: http://ftp.debian.org/debian/pool/main/p/python3-defaults/python3-defaults_3.6.6-1.tar.gz
92 | match := regexp.MustCompile("/debian/pool/(?:contrib|main|non-free)/[a-z]{1,4}/([^/#.]+)/[^/#]+(?:.tar|.deb)").FindStringSubmatch(url)
93 | if len(match) > 0 {
94 | return debian(match[1]).latestVersion()
95 | }
96 | case strings.Contains(url, "codeberg.org"):
97 | g := parseGitea("codeberg.org", url)
98 | if g == nil {
99 | break
100 | }
101 | return g.latestVersion()
102 | }
103 | return "", fmt.Errorf("No release found for %s", url)
104 | }
105 |
106 | // VersionForPkg determines the upstream version for the given package
107 | func VersionForPkg(pkg pkg.Pkg) (Version, error) {
108 | version, err := forURL(pkg.URL())
109 | if err == nil {
110 | return version, nil
111 | }
112 | sources, err := pkg.Sources()
113 | if err != nil {
114 | return "", fmt.Errorf("Failed to obtain sources for %s: %w", pkg.Name(), err)
115 | }
116 | if len(sources) > 0 {
117 | return forURL(sources[0])
118 | }
119 | return "", fmt.Errorf("No release found for %s: %w", pkg.Name(), err)
120 | }
121 |
122 | // VersionForScript runs the script using `sh -c` to determine the upstream version for the given package
123 | func VersionForScript(script string) (Version, error) {
124 | output, err := exec.Command("/bin/sh", "-c", script).Output()
125 | if err != nil {
126 | return "", fmt.Errorf("Failed to run script `%s`: %w", script, err)
127 | }
128 | v := string(output)
129 | v = strings.TrimSpace(v)
130 | return Version(v), nil
131 | }
132 |
133 | type releasesAPI interface {
134 | releasesURL() string
135 | latestVersion() (Version, error)
136 | }
137 |
138 | func fetchJSON(a releasesAPI, target interface{}) error {
139 | url := a.releasesURL()
140 | resp, err := http.Get(url)
141 | if err != nil {
142 | return err
143 | }
144 | defer resp.Body.Close()
145 |
146 | dec := json.NewDecoder(resp.Body)
147 | return dec.Decode(target)
148 | }
149 |
--------------------------------------------------------------------------------
/upstream/version_test.go:
--------------------------------------------------------------------------------
1 | package upstream
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestScript1(t *testing.T) {
8 | version, err := VersionForScript("echo 42")
9 | if err != nil {
10 | t.Error(err)
11 | }
12 | if version != "42" {
13 | t.Errorf("Expecting version 42, but got %v", version)
14 | }
15 | }
16 |
--------------------------------------------------------------------------------