Skip to content

Commit

Permalink
Меняет запрос к API на запрос к подготовленному файлу (#1253)
Browse files Browse the repository at this point in the history
* Добавляет исключение для файла со статистикой

* Удаляет сервис для работы с API GitHub

* Внедреяет сервис для формирования статистики
  • Loading branch information
igsekor authored Apr 30, 2024
1 parent d284a7a commit 78e5cf7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 342 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ interviews

# кеш для @11ty/eleventy-cache-assets
.cache
.issues.json

.env
294 changes: 0 additions & 294 deletions src/libs/github-contribution-service/github-contribution-service.js

This file was deleted.

35 changes: 35 additions & 0 deletions src/libs/github-contribution-stats/github-contribution-stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const issues = require('../../../.issues.json')

const stats = issues.reduce((result, issue) => {
const user = issue['user']['login'].toLowerCase()
const isPullRequest = 'pull_request' in issue
const pullRequestIncrement = isPullRequest ? 1 : 0
const issueIncrement = !isPullRequest ? 1 : 0
const pullRequestDate = isPullRequest ? new Date(issue['closed_at']) : new Date()

if (result && user in result) {
result[user]['issues'] += issueIncrement
result[user]['pr'] += pullRequestIncrement
if (result[user]['first'] > pullRequestDate) {
result[user]['first'] = pullRequestDate
}
return result
} else {
return {
...result,
[user]: {
issues: issueIncrement,
pr: pullRequestIncrement,
first: pullRequestDate,
},
}
}
}, {})

function getAuthorContributionStats() {
return stats
}

module.exports = {
getAuthorContributionStats,
}
21 changes: 7 additions & 14 deletions src/views/person.11tydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,14 @@ module.exports = {
},

badgesFields: function (data) {
const { authorData } = data

if (!authorData) {
return null
const { contributionStat } = data
const releaseDate = new Date('2021-10-12T00:00:00Z')
const theFirstDate = new Date('1970-01-01T00:00:00Z')
let pullRequestDate = releaseDate
if (contributionStat && !contributionStat['first'] === theFirstDate) {
pullRequestDate = contributionStat
}

const nodes = authorData?.contributionActions?.people?.target?.history?.nodes

const prNodes = nodes && nodes.length > 0 ? nodes[nodes.length - 1]?.associatedPullRequests?.nodes : null

const pullRequestDate =
prNodes && prNodes.length > 0 ? prNodes[prNodes.length - 1]?.mergedAt : '2021-10-12T00:00:00Z'

// TODO: Решить вопрос с датой для участников: Игорь Коровченко, Ольга Алексашенко
const githubFirstContribution = new Date(pullRequestDate)
const githubFirstContribution = pullRequestDate
.toLocaleString('ru', {
year: 'numeric',
month: 'long',
Expand Down
Loading

0 comments on commit 78e5cf7

Please sign in to comment.