Skip to content

Commit 45befbf

Browse files
committed
Track users with services so the same username on two different services aren't treated the same.
1 parent 3c49157 commit 45befbf

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

src/hook.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ function processVersions( repo, fn ) {
3636
Step(
3737
// get all tags for the repo
3838
function() {
39-
pluginsDb.getTags( repo.getId(), this.parallel() );
39+
pluginsDb.getTags( repo.id, this.parallel() );
4040
repo.getVersionTags( this.parallel() );
4141
},
4242

4343
// filter to new versions
4444
function( error, processedTags, tags ) {
4545
if ( error ) {
46-
retry.log( "processVersions", repo.getId() );
46+
retry.log( "processVersions", repo.id );
4747
return fn( error );
4848
}
4949

@@ -58,7 +58,7 @@ function processVersions( repo, fn ) {
5858
// get releases
5959
function( error, tags ) {
6060
if ( error ) {
61-
retry.log( "processVersions", repo.getId() );
61+
retry.log( "processVersions", repo.id );
6262
return fn( error );
6363
}
6464

@@ -76,7 +76,7 @@ function processVersions( repo, fn ) {
7676
// filter to valid releases
7777
function( error, tags, releases ) {
7878
if ( error ) {
79-
retry.log( "processVersions", repo.getId() );
79+
retry.log( "processVersions", repo.id );
8080
return fn( error );
8181
}
8282

@@ -88,15 +88,15 @@ function processVersions( repo, fn ) {
8888
}
8989

9090
// track invalid tags so we don't process them on each update
91-
pluginsDb.addTag( repo.getId(), tags[ i ], invalidGroup() );
91+
pluginsDb.addTag( repo.id, tags[ i ], invalidGroup() );
9292
return false;
9393
}));
9494
},
9595

9696
// process the releases
9797
function( error, releases ) {
9898
if ( error ) {
99-
retry.log( "processVersions", repo.getId() );
99+
retry.log( "processVersions", repo.id );
100100
return fn( error );
101101
}
102102

@@ -121,20 +121,20 @@ function processRelease( repo, release, fn ) {
121121
// find out who owns this plugin
122122
// if there is no owner, then set the user as the owner
123123
function() {
124-
pluginsDb.getOrSetOwner( release.package.name, repo.userName, this );
124+
pluginsDb.getOrSetOwner( release.package.name, repo.userId, this );
125125
},
126126

127127
// verify the user is the owner
128128
function( error, owner ) {
129129
if ( error ) {
130-
retry.log( "processRelease", repo.getId(), release.tag );
130+
retry.log( "processRelease", repo.id, release.tag );
131131
return fn( error );
132132
}
133133

134134
// the plugin is owned by someone else
135-
if ( owner !== repo.userName ) {
135+
if ( owner !== repo.userId ) {
136136
// TODO: report error to user
137-
logger.log( repo.userName + " attempted to add " + release.package.name + " which is owned by " + owner );
137+
logger.log( repo.userId + " attempted to add " + release.package.name + " which is owned by " + owner );
138138
return fn( null, null );
139139
}
140140

@@ -143,13 +143,13 @@ function processRelease( repo, release, fn ) {
143143

144144
// track the new release
145145
function( error, owner ) {
146-
pluginsDb.addRelease( repo.getId(), release, this );
146+
pluginsDb.addRelease( repo.id, release, this );
147147
},
148148

149149
// finished processing release
150150
function( error ) {
151151
if ( error ) {
152-
retry.log( "processRelease", repo.getId(), release.tag );
152+
retry.log( "processRelease", repo.id, release.tag );
153153
return fn( error );
154154
}
155155

@@ -167,23 +167,23 @@ function processMeta( repo, fn ) {
167167

168168
function( error, package ) {
169169
if ( error ) {
170-
retry.log( "processMeta", repo.getId() );
170+
retry.log( "processMeta", repo.id );
171171
return fn( error );
172172
}
173173

174174
if ( !package || !package.name ) {
175175
return fn( null );
176176
}
177177

178-
pluginsDb.updatePlugin( package.name, repo.userName, {
178+
pluginsDb.updatePlugin( package.name, repo.userId, {
179179
watchers: repo.watchers,
180180
forks: repo.forks
181181
}, this );
182182
},
183183

184184
function( error ) {
185185
if ( error ) {
186-
retry.log( "processMeta", repo.getId() );
186+
retry.log( "processMeta", repo.id );
187187
return fn( error );
188188
}
189189

src/service.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@ function extend( a, b ) {
88
}
99
}
1010

11-
function Repo() {}
12-
13-
extend( Repo.prototype, {
14-
getId: function() {
15-
return this.service + "/" + this.userName + "/" + this.repoName;
16-
},
17-
18-
getPath: function() {
19-
return config.repoDir + "/" + this.getId();
20-
}
21-
});
11+
function Repo() {
12+
this.userId = this.service + "/" + this.userName;
13+
this.id = this.userId + "/" + this.repoName;
14+
this.path = config.repoDir + "/" + this.id;
15+
}
2216

2317
// package.json
2418
extend( Repo.prototype, {

src/service/github.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ function GithubRepo( userName, repoName ) {
3939
this.repoName = repoName;
4040
this.siteUrl = "http://github.com" + partialPath;
4141
this.sourceUrl = "git://github.com" + partialPath + ".git";
42+
43+
service.Repo.call( this );
4244
}
4345

4446
GithubRepo.test = function( data ) {
@@ -66,7 +68,7 @@ extend( GithubRepo.prototype, {
6668
return fn( error );
6769
}
6870

69-
exec( "git tag", { cwd: repo.getPath() }, this );
71+
exec( "git tag", { cwd: repo.path }, this );
7072
},
7173

7274
// parse the tags
@@ -84,7 +86,7 @@ extend( GithubRepo.prototype, {
8486

8587
_getPackageJson: function( version, fn ) {
8688
version = version || "master";
87-
exec( "git show " + version + ":package.json", { cwd: this.getPath() }, function( error, stdout, stderr ) {
89+
exec( "git show " + version + ":package.json", { cwd: this.path }, function( error, stdout, stderr ) {
8890
// this will also result in an error being passed, so we check stderr first
8991
if ( stderr && stderr.substring( 0, 11 ) === "fatal: Path" ) {
9092
return fn( null, null );
@@ -99,7 +101,7 @@ extend( GithubRepo.prototype, {
99101
},
100102

101103
getReleaseDate: function( tag, fn ) {
102-
exec( "git log --pretty='%cD' -1 " + tag, { cwd: this.getPath() }, function( error, stdout ) {
104+
exec( "git log --pretty='%cD' -1 " + tag, { cwd: this.path }, function( error, stdout ) {
103105
if ( error ) {
104106
return fn( error );
105107
}
@@ -121,7 +123,7 @@ extend( GithubRepo.prototype, {
121123
Step(
122124
// make sure the user directory exists
123125
function() {
124-
mkdirp( dirname( repo.getPath() ), 0755, this );
126+
mkdirp( dirname( repo.path ), 0755, this );
125127
},
126128

127129
// check if the repo already exists
@@ -130,22 +132,22 @@ extend( GithubRepo.prototype, {
130132
return fn( error );
131133
}
132134

133-
fs.stat( repo.getPath(), this );
135+
fs.stat( repo.path, this );
134136
},
135137

136138
// create or update the repo
137139
function( error ) {
138140
// repo already exists
139141
if ( !error ) {
140-
return exec( "git fetch -t", { cwd: repo.getPath() }, this );
142+
return exec( "git fetch -t", { cwd: repo.path }, this );
141143
}
142144

143145
// error other than repo not existing
144146
if ( error.code !== "ENOENT" ) {
145147
return fn( error );
146148
}
147149

148-
exec( "git clone " + repo.sourceUrl + " " + repo.getPath(), this );
150+
exec( "git clone " + repo.sourceUrl + " " + repo.path, this );
149151
},
150152

151153
function( error ) {

0 commit comments

Comments
 (0)