Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NodeSecure/github
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.1
Choose a base ref
...
head repository: NodeSecure/github
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.1.0
Choose a head ref
  • 11 commits
  • 8 files changed
  • 6 contributors

Commits on Nov 7, 2021

  1. Copy the full SHA
    fb9f54b View commit details
  2. Copy the full SHA
    30fad5a View commit details

Commits on Jun 13, 2022

  1. Copy the full SHA
    d6be42b View commit details
  2. Copy the full SHA
    28cfeea View commit details
  3. Copy the full SHA
    cc4d206 View commit details

Commits on Jun 17, 2022

  1. chore(deps): bump undici from 5.5.0 to 5.5.1

    Bumps [undici](https://github.com/nodejs/undici) from 5.5.0 to 5.5.1.
    - [Release notes](https://github.com/nodejs/undici/releases)
    - [Commits](nodejs/undici@v5.5.0...v5.5.1)
    
    ---
    updated-dependencies:
    - dependency-name: undici
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jun 17, 2022
    Copy the full SHA
    9e2cad6 View commit details

Commits on Jun 20, 2022

  1. Merge pull request #81 from NodeSecure/dependabot/npm_and_yarn/undici…

    …-5.5.1
    
    chore(deps): bump undici from 5.5.0 to 5.5.1
    tony-go authored Jun 20, 2022
    Copy the full SHA
    80d8fa0 View commit details

Commits on Jul 1, 2022

  1. feat: get repository contributors last activities (#82)

    * feat: get repository contributors last activities
    Rossb0b authored Jul 1, 2022
    Copy the full SHA
    7f36895 View commit details
  2. Copy the full SHA
    4ec079a View commit details
  3. docs: add Rossb0b as a contributor for code (#83)

    * docs: update README.md [skip ci]
    
    * docs: update .all-contributorsrc [skip ci]
    
    Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
    allcontributors[bot] authored Jul 1, 2022
    Copy the full SHA
    6b7ae68 View commit details
  4. 1.1.0

    fraxken committed Jul 1, 2022
    Copy the full SHA
    b897870 View commit details
Showing with 8,184 additions and 3,268 deletions.
  1. +19 −0 .all-contributorsrc
  2. +46 −0 CONTRIBUTING.md
  3. +22 −1 README.md
  4. +17 −0 index.d.ts
  5. +72 −0 index.js
  6. +7,953 −3,257 package-lock.json
  7. +10 −10 package.json
  8. +45 −0 test/test.js
19 changes: 19 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -17,6 +17,25 @@
"security",
"bug"
]
},
{
"login": "AlexandreMalaj",
"name": "Alexandre Malaj",
"avatar_url": "https://avatars.githubusercontent.com/u/32218832?v=4",
"profile": "https://github.com/AlexandreMalaj",
"contributions": [
"code",
"doc"
]
},
{
"login": "Rossb0b",
"name": "Nicolas Hallaert",
"avatar_url": "https://avatars.githubusercontent.com/u/39910164?v=4",
"profile": "https://www.linkedin.com/in/nicolas-hallaert/",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributing to NodeSecure

Contributions to NodeSecure include code, documentation, answering user questions and
running the project's infrastructure

The NodeSecure project welcomes all contributions from anyone willing to work in
good faith with other contributors and the community. No contribution is too
small and all contributions are valued.

This guide explains the process for contributing to the NodeSecure project's.

## [Code of Conduct](https://github.com/NodeSecure/Governance/blob/main/CODE_OF_CONDUCT.md)

The NodeSecure project has a
[Code of Conduct](https://github.com/NodeSecure/Governance/blob/main/CODE_OF_CONDUCT.md)
that *all* contributors are expected to follow. This code describes the
*minimum* behavior expectations for all contributors.

See [details on our policy on Code of Conduct](https://github.com/NodeSecure/Governance/blob/main/COC_POLICY.md).

<a id="developers-certificate-of-origin"></a>
## Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

* (a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

* (b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

* (c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

* (d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -30,6 +30,9 @@ console.log(utils.location);

const scanner = await github.downloadAndExtract("NodeSecure.scanner");
console.log(scanner.location);

const contributors = await github.getContributorsLastActivities("NodeSecure", "scanner");
console.log(contributors);
```

## API
@@ -74,8 +77,24 @@ export interface DownloadResult {
organization: string;
}

export interface GetContributorsLastActivities {
token?: string;
}

export interface GetContributorsLastActivitiesResult {
[key: string]: {
repository: string;
actualRepo: boolean,
lastActivity: string;
}[];
}
export function download(repo: string, options?: DownloadOptions): Promise<DownloadResult>;
export function downloadAndExtract(repo: string, options?: ExtractOptions): Promise<DownloadResult>;
export function getContributorsLastActivities(
owner: string,
repository: string,
options?: GetContributorsLastActivities
): Promise<GetContributorsLastActivitiesResult | null>;
export function setToken(githubToken: string): void;
```

@@ -91,7 +110,7 @@ github.setToken("...");
## Contributors ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -102,6 +121,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<table>
<tr>
<td align="center"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/NodeSecure/github/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/NodeSecure/github/commits?author=fraxken" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/github/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="#security-fraxken" title="Security">🛡️</a> <a href="https://github.com/NodeSecure/github/issues?q=author%3Afraxken" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/AlexandreMalaj"><img src="https://avatars.githubusercontent.com/u/32218832?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alexandre Malaj</b></sub></a><br /><a href="https://github.com/NodeSecure/github/commits?author=AlexandreMalaj" title="Code">💻</a> <a href="https://github.com/NodeSecure/github/commits?author=AlexandreMalaj" title="Documentation">📖</a></td>
<td align="center"><a href="https://www.linkedin.com/in/nicolas-hallaert/"><img src="https://avatars.githubusercontent.com/u/39910164?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nicolas Hallaert</b></sub></a><br /><a href="https://github.com/NodeSecure/github/commits?author=Rossb0b" title="Code">💻</a></td>
</tr>
</table>

17 changes: 17 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -37,6 +37,23 @@ export interface DownloadResult {
organization: string;
}

export interface GetContributorsLastActivities {
token?: string;
}

export interface GetContributorsLastActivitiesResult {
[key: string]: {
repository: string;
actualRepo: boolean,
lastActivity: string;
}[];
}

export function download(repo: string, options?: DownloadOptions): Promise<DownloadResult>;
export function downloadAndExtract(repo: string, options?: ExtractOptions): Promise<DownloadResult>;
export function getContributorsLastActivities(
owner: string,
repository: string,
options?: GetContributorsLastActivities
): Promise<GetContributorsLastActivitiesResult | null>;
export function setToken(githubToken: string): void;
72 changes: 72 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import httpie from "@myunisoft/httpie";

// CONSTANTS
const kGithubURL = new URL("https://github.com/");
const kGithubApi = new URL("https://api.github.com/");
const kDefaultBranch = "main";

// VARS
@@ -78,6 +79,77 @@ export async function downloadAndExtract(repository, options = Object.create(nul
return result;
}

export async function getContributorsLastActivities(owner, repository, options = Object.create(null)) {
if (typeof owner !== "string") {
throw new TypeError(`owner must be a string, but got ${owner}`);
}

if (typeof repository !== "string") {
throw new TypeError(`repository must be a string, but got ${repository}`);
}

const { token } = options;

const contributorsUrl = new URL(`repos/${owner}/${repository}/contributors`, kGithubApi);

try {
const { data } = await httpie.get(contributorsUrl, {
headers: {
"User-Agent": "NodeSecure",
Authorization: typeof token === "string" ? `token ${token}` : GITHUB_TOKEN
},
maxRedirections: 1
});

const contributors = data.filter((contributor) => !/bot/.test(contributor.login))
.map((contributor) => hydrateLastActivities(contributor.login, owner, repository));

const lastActivities = new Map(await Promise.all(contributors));

return lastActivities;
}
catch (error) {
return null;
}
}

async function hydrateLastActivities(contributor, owner, repository) {
const formatedRepositoryName = `${owner}/${repository}`;

const eventsUrl = new URL(`users/${contributor}/events`, kGithubApi);

const { data } = await httpie.get(eventsUrl, {
headers: {
"User-Agent": "NodeSecure",
Authorization: typeof token === "string" ? `token ${token}` : GITHUB_TOKEN
},
maxRedirections: 1
});

function getLastEvents(events) {
const lastEvent = events[0];
const lastRelatedEvent = events.find((event) => event.repo.name === formatedRepositoryName);

if (lastEvent.repo.name === formatedRepositoryName) {
return [lastEvent];
}

return lastRelatedEvent ?
[lastEvent, lastRelatedEvent] : [lastEvent];
}

return [contributor,
[...getLastEvents(data)]
.map((event) => {
return {
repository: event.repo.name,
actualRepo: event.repo.name === formatedRepositoryName,
lastActivity: event.created_at
};
})
];
}

export function setToken(githubToken) {
GITHUB_TOKEN = githubToken;
}
Loading