Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GitHub] latest release badge #1122

Merged
merged 12 commits into from
Oct 4, 2017
Merged

Conversation

ritwickdey
Copy link
Contributor

pull request #905

Hi, please review the code. I've separated the code to lib/github-provider.js & made few modification on it.

[the branch was too old, I've managed conflicting code & removed few code with standard function]

Please guide me for further changes. [I have not yet added tests. I'll add it by tommrow & for now please ingore the lint issue. I'll fix it then.]

agboom and others added 4 commits March 27, 2017 20:54
- Badge shows readable format of release date of latest version
- Color fades with age of release
const colorB = makeColorB('#007ec6', data ); // blue
const baseColor = Color(colorB);
const weeksSinceRelease = moment().diff(releaseDate, 'weeks');
const factor = Math.max(Math.min(weeksSinceRelease / 25, 0.9), 0.1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't ask me about this 😊😊😊....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the color scheme provided by age in color-formatters seem reasonable enough to use here, instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but that is not lighten or brighten color. Anyways, I am cleaning the existing code with age function

Copy link
Member

@paulmelnikow paulmelnikow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up!

try {
const data = JSON.parse(buffer);

if (!data.created_at) throw 'Project has no releases';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of throwing, this should return a badge with a helpful message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, problem is that data is always a object even if the the repo is the exist. So, data.created_at will not throw any error as it will be always null or a valid value.

If you think, we should return a valid message, then I've to check the status code first then data.created_at. -- NO PROBLEM AT ALL.

Should i do this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I gotcha. Yes, it'd be better to add a test for a nonexistent repo, determine how to detect that condition, and return a useful message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok! Then, I should check the returned status code

sameDay : '[Today]',
lastWeek : '[last] dddd',
sameElse : now => releaseDate.year() == now.year() ? 'D MMM' : 'D MMM YYYY'
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use formatDate from text-formatters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the code it is already exists. 😃 ..

const colorB = makeColorB('#007ec6', data ); // blue
const baseColor = Color(colorB);
const weeksSinceRelease = moment().diff(releaseDate, 'weeks');
const factor = Math.max(Math.min(weeksSinceRelease / 25, 0.9), 0.1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the color scheme provided by age in color-formatters seem reasonable enough to use here, instead?

server.js Outdated
@@ -3323,6 +3324,9 @@ cache(function(data, match, sendBadge, request) {
});
}));

// GitHub release date integration.
mapGithubReleaseDate(camp, githubApiUrl, githubAuth)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add service tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, just saw your note about that!

@paulmelnikow paulmelnikow added the service-badge New or updated service badge label Oct 2, 2017

const { handleRequest: cache } = require('./request-handler');
const {
makeBadgeData: getBadgeData,
makeLabel: getLabel,
getLogo
makeLogo: getLogo,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I made a mistake on previous pull request. I didn't noticed that getLogo is not defined in badge-data. It is alias of makeLogo

//github return 404 if repo not found or no release
if(res.statusCode === 404) {
badgeData.text[1] = 'not found';
sendBadge(format, badgeData);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it good to return not found ? or just invalid??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, no releases or repo not found would be clearer than invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big String ^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's helpful though! It tells the user what could be wrong.

@ritwickdey
Copy link
Contributor Author

Hahaha Travis CI still in pending 🌞

@paulmelnikow
Copy link
Member

I kicked the build. It's running now.

package.json Outdated
@@ -24,6 +24,7 @@
"dependencies": {
"camp": "~16.2.3",
"chrome-web-store-item-property": "~1.1.2",
"color": "^1.0.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Oop! I forget to remove that.

t.create('Release Date. e.g release date|today')
.get('/release-date/microsoft/vscode.json')
.expectJSONTypes(Joi.object().keys({
name: Joi.equal('release date'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this and the one below to e.g. name: 'release date'. I've gone ahead and done with the existing tests in #1127.

.get('/release-date/not-valid-name/not-valid-repo.json')
.expectJSONTypes(Joi.object().keys({
name: Joi.equal('release date'),
value: 'no releases or repo not found'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are both hard-coded, it can be written like this:

.expectJSON({ name: 'release date', value: 'no releases or repo not found' })

@ritwickdey
Copy link
Contributor Author

Not ready yet.

@ritwickdey
Copy link
Contributor Author

ready.

@tooomm
Copy link
Contributor

tooomm commented Oct 4, 2017

Will this account for any release?
Or just "full" releases (not pre-releases)?

@ritwickdey
Copy link
Contributor Author

hi, @tooomm full release

@ritwickdey ritwickdey changed the title [GitHub] last release badge [GitHub] latest release badge Oct 4, 2017
@tooomm
Copy link
Contributor

tooomm commented Oct 4, 2017

Does it makes sense to extend this for
https://img.shields.io/github/prerelease-date/SubtitleEdit/subtitleedit.svg

Many repos use pre-releases to distribute betas next to stable releases.
It would be handy to list a date badge for both independently.

@ritwickdey
Copy link
Contributor Author

yep! right! okay I'll add. Lets wait for what @paulmelnikow says - should I open a different pull request on it or it will be included here? (I am saying because this PR is extended from #905)

Btw, I think, there is no explicit API for getting latest pre-release version.

@tooomm
Copy link
Contributor

tooomm commented Oct 4, 2017

Btw, I think, there is no explicit API for getting latest pre-release version.

You might be right there. For displaying releases it works like that:

GitHub release:   | https://img.shields.io/github/release/qubyte/rubidium.svg
GitHub (pre-)release: | https://img.shields.io/github/release/qubyte/rubidium/all.svg

So it looks like one just displays all releases (including pre-releases) and the first just displays full releases.
As long as there is no newer pre-release both show the same - as in the example on the shields page.

Example with a different pre-release as seen in a readme on github:
pre-release

@paulmelnikow
Copy link
Member

Github service tests passing locally.

That's a great idea to add prerelease-date. Let's do it in a separate PR so we can close this out!

Thanks for all your work on this! 🏅

@paulmelnikow paulmelnikow merged commit e7f1f57 into badges:master Oct 4, 2017
@tooomm
Copy link
Contributor

tooomm commented Oct 4, 2017

If you keep on looking into that prerelease date, please @ link me when you open the PR.
I happily get informed about any progress! 👍

@ritwickdey
Copy link
Contributor Author

Hi @tooomm , #1133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants