Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ Start command palette (with <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> or <kb

```JavaScript
{
// Number of seconds the list of `.gitignore` files retrieved from github will be cached
"gitignore.cacheExpirationInterval": 3600
// Number of seconds the list of `.gitignore` files retrieved from GitHub will be cached.
"gitignore.cacheExpirationInterval": 3600,
// Prepend a comment with the URL to the file on GitHub.
"gitignore.includeUrl": false
}
```

Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
"gitignore.cacheExpirationInterval": {
"type": "integer",
"default": 3600,
"description": "Number of seconds the list of `.gitignore` files retrieved from github will be cached"
"description": "Number of seconds the list of `.gitignore` files retrieved from GitHub will be cached."
},
"gitignore.includeUrl": {
"type": "boolean",
"default": false,
"description": "Prepend a comment with the URL to the file on GitHub."
}
}
},
Expand Down Expand Up @@ -76,7 +81,8 @@
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
"test": "node ./out/test/runTest.js",
"test:headless": "xvfb-run -a npm run test"
},
"devDependencies": {
"@types/glob": "^7.2.0",
Expand Down
5 changes: 1 addition & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Cache } from './cache';
import { GitignoreTemplate, GitignoreOperation, GitignoreOperationType, GitignoreProvider } from './interfaces';
import { GithubGitignoreRepositoryProvider } from './providers/github-gitignore-repository';


class CancellationError extends Error {

}
Expand All @@ -15,15 +14,13 @@ interface GitignoreQuickPickItem extends vscode.QuickPickItem {
template: GitignoreTemplate;
}


// Initialize
const config = vscode.workspace.getConfiguration('gitignore');
const cache = new Cache(config.get('cacheExpirationInterval', 3600));

// Create gitignore repository provider
const gitignoreRepository: GitignoreProvider = new GithubGitignoreRepositoryProvider(cache);
//const gitignoreRepository : GitignoreProvider = new GithubGitignoreApiProvider(cache);

// const gitignoreRepository: GitignoreProvider = new GithubGitignoreApiProvider(cache);

/**
* Resolves the workspace folder by
Expand Down
9 changes: 8 additions & 1 deletion src/providers/github-gitignore-api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as vscode from 'vscode';
import * as https from 'https';
import * as fs from 'fs';
import * as url from 'url';
import { WriteStream } from 'fs';


import { Cache, CacheItem } from '../cache';
import { GitignoreProvider, GitignoreTemplate, GitignoreOperation, GitignoreOperationType } from '../interfaces';
import { getAgent, getDefaultHeaders } from '../http-client';
Expand Down Expand Up @@ -86,6 +86,13 @@ export class GithubGitignoreApiProvider implements GitignoreProvider {
file.write('\n');
}

const config = vscode.workspace.getConfiguration('gitignore');
const includeUrl = config.get('includeUrl', false);

if (includeUrl) {
file.write(`# https://github.com/github/gitignore/blob/main/${operation.template.path}\n`);
}

/*
curl \
-H "Accept: application/vnd.github.v3.raw" \
Expand Down
8 changes: 8 additions & 0 deletions src/providers/github-gitignore-repository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as vscode from 'vscode';
import * as https from 'https';
import * as fs from 'fs';
import * as url from 'url';
Expand Down Expand Up @@ -120,6 +121,13 @@ export class GithubGitignoreRepositoryProvider implements GitignoreProvider {
file.write('\n');
}

const config = vscode.workspace.getConfiguration('gitignore');
const includeUrl = config.get('includeUrl', false);

if (includeUrl) {
file.write(`# https://github.com/github/gitignore/blob/main/${operation.template.path}\n`);
}

/*
curl \
-H "Accept: application/vnd.github.v3.raw" \
Expand Down