-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a README.md file containing information about the project,including steps for Installation,languages,usage,getting involved,Support,Authors,and License.It helps users to setup and use this project. Closes #2
- Loading branch information
1 parent
8f027dd
commit e8a225f
Showing
30 changed files
with
11,659 additions
and
4,315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ env: | |
jquery: true | ||
parserOptions: | ||
ecmaVersion: 2017 | ||
sourceType: module | ||
plugins: | ||
- prettier | ||
extends: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
node_modules | ||
out/* | ||
!out/.keep | ||
out | ||
yarn.lock | ||
.DS_Store | ||
**.orig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Google Code-in Leaders | ||
*** | ||
This is a website to show the current leaders from all organizations in GCI. | ||
*** | ||
* [Installation](#installation) | ||
* [Languages](#languages) | ||
* [Usage](#usage) | ||
* [Getting Involved](#getting-involved) | ||
* [Support](#support) | ||
* [Authors](#authors) | ||
* [License](#license) | ||
*** | ||
### Installation | ||
``` | ||
npm install | ||
``` | ||
*** | ||
### Languages: | ||
* Node.js | ||
* JSON | ||
*** | ||
### Usage: | ||
``` | ||
npm run build | ||
``` | ||
*** | ||
### Getting Involved | ||
If you would like to be a part of the coala community, you can check out our [Getting In Touch](http://coala.readthedocs.io/en/latest/Help/Getting_In_Touch.html) page or ask us at our active Gitter channel, where we have maintainers from all over the world. We appreciate any help! | ||
*** | ||
### Support | ||
Feel free to contact us at our [Gitter channel](https://gitter.im/coala/coala), we'd be happy to help! | ||
*** | ||
### Authors | ||
You can contact to author for more information. | ||
[blazeu](mailto:[email protected]) | ||
*** | ||
### License | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
*** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
const fetch = require('node-fetch') | ||
const fs = require('fs') | ||
|
||
const GITHUB_CONTENT = 'https://raw.githubusercontent.com' | ||
|
||
async function getData() { | ||
const res = await fetch( | ||
'https://raw.githubusercontent.com/coala/gci-leaders/gh-pages/data.min.json' | ||
`${GITHUB_CONTENT}/coala/gci-leaders/gh-pages/data.min.json` | ||
) | ||
|
||
try { | ||
const data = await res.json() | ||
fs.writeFileSync(`${__dirname}/../out/data.min.json`, JSON.stringify(data)) | ||
} catch (e) { | ||
console.warn('Could not gather data.min.json') | ||
} | ||
} | ||
|
||
async function getFeedItems() { | ||
const res = await fetch( | ||
`${GITHUB_CONTENT}/coala/gci-leaders/gh-pages/feed_items.json` | ||
) | ||
|
||
const data = await res.json() | ||
fs.writeFileSync(`${__dirname}/../out/data.min.json`, JSON.stringify(data)) | ||
try { | ||
const items = await res.json() | ||
fs.writeFileSync( | ||
`${__dirname}/../out/feed_items.json`, | ||
JSON.stringify(items) | ||
) | ||
} catch (e) { | ||
console.warn('Could not gather feed_items.json') | ||
} | ||
} | ||
|
||
getData() | ||
getFeedItems() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const glob = require('glob') | ||
const fs = require('fs') | ||
|
||
const rss = require('./rss') | ||
;(async () => { | ||
const files = glob.sync(`${__dirname}/../out/*.json`) | ||
const fileContents = files.map(f => JSON.parse(fs.readFileSync(f).toString())) | ||
|
||
const data = {} | ||
files.forEach((f, index) => { | ||
const name = f.split('/')[f.split('/').length - 1].replace('.json', '') | ||
data[name] = fileContents[index] | ||
}) | ||
|
||
data.data_updated = fs.statSync(`${__dirname}/../out/data.json`).mtime | ||
|
||
const rssResult = rss(data) | ||
fs.writeFileSync(`${__dirname}/../out/feed_items.json`, rssResult.feed_items) | ||
fs.writeFileSync(`${__dirname}/../out/feed.xml`, rssResult.feed_xml) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
const RSS = require('rss') | ||
const generateDiff = require('deep-diff').diff | ||
|
||
function createLeadersHash(array) { | ||
return array.reduce((hash, elem) => { | ||
hash[elem.id] = elem | ||
return hash | ||
}, {}) | ||
} | ||
|
||
function createOrgHash(array) { | ||
let rank = 0 | ||
return array.reduce((hash, elem) => { | ||
rank++ | ||
elem.rank = rank | ||
elem.leaders = createLeadersHash(elem.leaders) | ||
hash[elem.slug] = elem | ||
return hash | ||
}, {}) | ||
} | ||
|
||
module.exports = ({ | ||
data: newData, | ||
data_old: oldData, | ||
feed_items: current, | ||
data_updated: dataUpdated, | ||
}) => { | ||
const oldOrgs = createOrgHash(oldData) | ||
const newOrgs = createOrgHash(newData) | ||
|
||
if (oldOrgs && newOrgs) { | ||
const diffs = generateDiff(oldOrgs, newOrgs) || [] | ||
|
||
const feedItems = current ? current.items : [] | ||
|
||
const currentUpdated = new Date(current ? current.lastUpdated : '') | ||
if (currentUpdated.getTime() !== dataUpdated.getTime()) { | ||
diffs.forEach(({ kind, path, lhs, rhs, item }) => { | ||
const organization = oldOrgs[path[0]] | ||
|
||
const itemPath = path.slice(1) | ||
const stringPath = itemPath.join('/') | ||
const finalProperty = itemPath[itemPath.length - 1] | ||
|
||
let title = '' | ||
|
||
if (itemPath[0] === 'leaders' && itemPath.length === 2) { | ||
if (kind === 'N') { | ||
title = `New Leader for ${organization.name}` | ||
} else if (kind === 'D') { | ||
title = `Leader Removed from ${organization.name}` | ||
} | ||
|
||
const user = rhs || lhs | ||
|
||
return feedItems.push({ | ||
title, | ||
description: `${organization.name} ${ | ||
kind === 'N' ? 'added' : 'removed' | ||
} ${user.display_name} ${ | ||
kind === 'N' ? 'to' : 'from' | ||
} the leaderboard.`, | ||
date: dataUpdated, | ||
custom_elements: [ | ||
{ | ||
'org:name': organization.name, | ||
}, | ||
{ | ||
'org:slug': organization.slug, | ||
}, | ||
{ | ||
'org:id': organization.id, | ||
}, | ||
{ | ||
'property:path': stringPath, | ||
}, | ||
{ | ||
'property:type': kind === 'N' ? 'addition' : 'deletion', | ||
}, | ||
{ | ||
'property:display_name': user.display_name, | ||
}, | ||
{ | ||
'property:id': user.id, | ||
}, | ||
{ | ||
'property:github_account': user.github_account, | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
if (itemPath[0] === 'leaders') { | ||
return | ||
} | ||
|
||
if (finalProperty === 'completed_task_instance_count') { | ||
title = `Completed Tasks Updated for ${organization.name}` | ||
} else if (finalProperty === 'rank') { | ||
title = `Organization Rank Updated for ${organization.name}` | ||
} else { | ||
title = `Updated "${finalProperty}" for ${organization.name}` | ||
} | ||
|
||
if (kind === 'A') { | ||
return feedItems.push({ | ||
title, | ||
date: dataUpdated, | ||
custom_elements: [ | ||
{ | ||
'org:name': organization.name, | ||
}, | ||
{ | ||
'org:slug': organization.slug, | ||
}, | ||
{ | ||
'org:id': organization.id, | ||
}, | ||
{ | ||
'property:path': stringPath, | ||
}, | ||
{ | ||
'property:type': item.kind === 'N' ? 'addition' : 'deletion', | ||
}, | ||
{ | ||
'property:item': item.rhs, | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
return feedItems.push({ | ||
title, | ||
description: `${ | ||
organization.name | ||
} changed ${finalProperty} from ${lhs} to ${rhs}.`, | ||
date: dataUpdated, | ||
custom_elements: [ | ||
{ | ||
'org:name': organization.name, | ||
}, | ||
{ | ||
'org:slug': organization.slug, | ||
}, | ||
{ | ||
'org:id': organization.id, | ||
}, | ||
{ | ||
'property:path': stringPath, | ||
}, | ||
{ | ||
'property:type': 'change', | ||
}, | ||
{ | ||
'property:old': lhs, | ||
}, | ||
{ | ||
'property:new': rhs, | ||
}, | ||
], | ||
}) | ||
}) | ||
|
||
const feed = new RSS({ | ||
title: 'Google Code-in Leaders', | ||
description: 'A feed for Google Code-in updates', | ||
site_url: process.env.URL || 'https://gci-leaders.netlify.com', | ||
feed_url: `${process.env.URL || | ||
'https://gci-leaders.netlify.com'}/feed.xml`, | ||
pubDate: new Date(), | ||
custom_namespaces: { | ||
org: 'https://g.co/gci', | ||
property: 'https://g.co/gci', | ||
}, | ||
}) | ||
|
||
feedItems.forEach(item => feed.item(item)) | ||
|
||
const feedData = { | ||
items: feedItems, | ||
lastUpdated: dataUpdated, | ||
} | ||
|
||
return { | ||
feed_items: JSON.stringify(feedData), | ||
feed_xml: feed.xml(), | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.